e-commercee
Version:
This package contains a backend of what would be the logic of a e-commercee software, the architecture used is made in 3 layers
126 lines • 5.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DClient = void 0;
const Client_1 = require("../../shared/entity/Client");
const dataexception_1 = require("../../shared/exceptions/dataexception");
const Conection_1 = require("../Conection");
class DClient {
constructor() { }
static getInstance() {
if (!DClient.instancia) {
DClient.instancia = new DClient();
}
return DClient.instancia;
}
async addClient(dtclient) {
try {
let cn = await Conection_1.Conexion.uri().connect();
const collection = cn.db("ECommerce").collection("Client");
const result = await collection.insertOne(dtclient);
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Client could not be added" + e.message);
}
}
async getClient(idcard) {
let cliobj = null;
try {
let cn = await Conection_1.Conexion.uri().connect();
const collection = cn.db("ECommerce").collection("Client");
const client = await collection.findOne({ _identitycard: idcard });
if (client == null) {
return null;
}
cliobj = new Client_1.Client(client._salt, client._identitycard, client._completename, client._password, client._username, client._shippingaddress, client._creditcardnumber);
return cliobj;
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Client could not be searched");
}
}
async getClientbyusername(username) {
let cliobj = null;
try {
let cn = await Conection_1.Conexion.uri().connect();
const collection = cn.db("ECommerce").collection("Client");
const client = await collection.findOne({ _username: username });
if (client == null) {
return null;
}
cliobj = new Client_1.Client(client._salt, client._identitycard, client._completename, client._password, client._username, client._shippingaddress, client._creditcardnumber);
return cliobj;
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Client could not be searched");
}
}
async loginClient(username, password) {
let cliobj = null;
try {
let cn = await Conection_1.Conexion.uri().connect();
const collection = cn.db("ECommerce").collection("Client");
const client = await collection.findOne({ _username: username, _password: password });
if (client == null) {
return null;
}
cliobj = new Client_1.Client(client._salt, client._identitycard, client._completename, client._password, client._username, client._shippingaddress, client._creditcardnumber);
return cliobj;
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Client could not be searched");
}
}
async updateClient(dtclient) {
try {
let cn = await Conection_1.Conexion.uri().connect();
let query = { _identitycard: dtclient.identitycard };
var newvalues = { $set: { _completename: dtclient.completename,
_password: dtclient.password,
_salt: dtclient.salt,
_shippingaddress: dtclient.shippingaddress,
_creditcardnumber: dtclient.creditcardnumber,
} };
const coladvert = cn.db("ECommerce").collection("Client");
const result = await coladvert.updateOne(query, newvalues);
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Client could not be updated" + e.message);
}
}
async deleteClient(dtclient) {
try {
let cn = await Conection_1.Conexion.uri().connect();
let query = { _identitycard: dtclient.identitycard };
const colcat = cn.db("ECommerce").collection("Client");
const result = await colcat.deleteOne(query);
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Client could not be deleted" + e.message);
}
}
async getClients() {
try {
let cn = await Conection_1.Conexion.uri().connect();
const collection = cn.db("ECommerce").collection("Client");
const result = await collection.find({}).toArray();
let array = [];
for (var client of result) {
var cliobj = new Client_1.Client(client._salt, client._identitycard, client._completename, client._password, client._username, client._shippingaddress, client._creditcardnumber);
array.push(cliobj);
}
return array;
cn.close();
}
catch (e) {
throw new dataexception_1.DataException("Clients could not be listed" + e.message);
}
}
}
exports.DClient = DClient;
//# sourceMappingURL=DClient.js.map