UNPKG

opencart-manager

Version:

Node.js package helping to manage your opencart store data easily.

78 lines (77 loc) 3.29 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const category_1 = __importDefault(require("../entities/category")); class CategoryFactory { constructor(model) { this.model = model; } create() { return new category_1.default(this.model); } extract(criteria) { return __awaiter(this, void 0, void 0, function* () { const rowsData = yield this.model.category.select(criteria); return this.createEntityFromRowData(rowsData[0]); }); } extractAll(criteria) { return __awaiter(this, void 0, void 0, function* () { const rowsData = yield this.model.category.select(criteria); const entities = []; for (const rowData of rowsData) { const entity = yield this.createEntityFromRowData(rowData); if (entity) { entities.push(entity); } } return entities; }); } createEntityFromRowData(rowData) { return __awaiter(this, void 0, void 0, function* () { if (!rowData) return undefined; const { categoryId } = rowData; const descriptionRowData = yield this.model.category.description.select({ categoryId, }); const entity = new category_1.default(this.model, categoryId); entity.setData({ image: rowData.image, parentId: rowData.parentId, top: rowData.top, column: rowData.column, sortOrder: rowData.sortOrder, status: rowData.status, dateAdded: rowData.dateAdded, dateModified: rowData.dateModified, }); descriptionRowData.forEach((row) => { entity.setDescription({ languageId: row.languageId, categoryId: row.categoryId, name: row.name, description: row.description, metaTitle: row.metaTitle, metaH1: row.metaH1, metaDescription: row.metaDescription, metaKeyword: row.metaKeyword, }); }); return entity; }); } } exports.default = CategoryFactory;