UNPKG

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

88 lines 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LCategory = void 0; const FactoryData_1 = require("../../data/FactoryData"); const logicexception_1 = require("../../shared/exceptions/logicexception"); class LCategory { constructor() { } static getInstance() { if (!LCategory.instancia) { LCategory.instancia = new LCategory(); } return LCategory.instancia; } //Validations************************************ validateName(name) { if (name.trim() === "") { throw new logicexception_1.LogicException("The name cannot be empty"); } } async validateAddCategory(dtcat) { this.validateName(dtcat.name); let objsearchcat = await this.getCategory(dtcat.name); if (dtcat == null) { throw new logicexception_1.LogicException("The Category is empty "); } if (objsearchcat != null) { throw new logicexception_1.LogicException("That Category already exists in the system"); } if (dtcat.description.trim() === "") { throw new logicexception_1.LogicException("The description cannot be empty"); } } async validateUpdateCategory(dtcat) { this.validateName(dtcat.name); let objsearchcat = await this.getCategory(dtcat.name); if (dtcat == null) { throw new logicexception_1.LogicException("The Category is empty "); } if (objsearchcat == null) { throw new logicexception_1.LogicException("That Category does not exists in the system"); } if (dtcat.description.trim() === "") { throw new logicexception_1.LogicException("The description cannot be empty"); } } async validateDeleteCategory(dtcat) { this.validateName(dtcat.name); let objsearchcat = await this.getCategory(dtcat.name); if (dtcat === null) { throw new logicexception_1.LogicException("The Category is empty "); } if (objsearchcat === null) { throw new logicexception_1.LogicException("That Category does not exists in the system"); } } //*********************************************** */ //Functions async getCategory(name) { this.validateName(name); var searchcategory = await FactoryData_1.FactoryData.getDCategory().getCategory(name); return searchcategory; } async addCategory(dtcategory) { await this.validateAddCategory(dtcategory); FactoryData_1.FactoryData.getDCategory().addCategory(dtcategory); } async updateCategory(dtcategory) { await this.validateUpdateCategory(dtcategory); FactoryData_1.FactoryData.getDCategory().updateCategory(dtcategory); } async deleteCategory(dtcategory) { await this.validateDeleteCategory(dtcategory); FactoryData_1.FactoryData.getDCategory().deleteCategory(dtcategory); } async getCategorysByNameLetter(expression) { if (expression === undefined) { return this.getCategories(); } var listexp = await FactoryData_1.FactoryData.getDCategory().getCategorysByNameLetter(expression); return listexp; } async getCategories() { var list = await FactoryData_1.FactoryData.getDCategory().getCategories(); return list; } } exports.LCategory = LCategory; //# sourceMappingURL=LCategory.js.map