opencart-manager
Version:
Node.js package helping to manage your opencart store data easily.
76 lines (75 loc) • 3.85 kB
JavaScript
"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 initial_1 = require("../../initial");
const utils_1 = require("../../utils");
const product_attribute_1 = __importDefault(require("./product-attribute"));
const product_description_1 = __importDefault(require("./product-description"));
const product_image_1 = __importDefault(require("./product-image"));
const product_option_1 = __importDefault(require("./product-option"));
const product_special_1 = __importDefault(require("./product-special"));
class ProductModel {
constructor(database) {
this.database = database;
this.table = "product";
this.description = new product_description_1.default(this.database);
this.option = new product_option_1.default(this.database);
this.attribute = new product_attribute_1.default(this.database);
this.special = new product_special_1.default(this.database);
this.image = new product_image_1.default(this.database);
}
select(criteria) {
return __awaiter(this, void 0, void 0, function* () {
const criteriaFieldset = utils_1.toFieldset(criteria);
return this.database.select(this.table, criteriaFieldset);
});
}
insert(data) {
return __awaiter(this, void 0, void 0, function* () {
const dataFieldset = utils_1.toFieldset(Object.assign(Object.assign({}, initial_1.initialProduct), data));
return this.database.insert(this.table, dataFieldset);
});
}
update(criteria, data) {
return __awaiter(this, void 0, void 0, function* () {
const criteriaFieldset = utils_1.toFieldset(criteria);
const dataFieldset = utils_1.toFieldset(data);
return this.database.update(this.table, criteriaFieldset, dataFieldset);
});
}
delete(criteria) {
return __awaiter(this, void 0, void 0, function* () {
const criteriaFieldset = utils_1.toFieldset(criteria);
const { productId } = criteriaFieldset;
if (productId) {
this.database.delete(`${this.table}_to_category`, { productId });
this.database.delete(`${this.table}_to_store`, { productId });
}
return this.database.delete(this.table, criteriaFieldset);
});
}
toCategory(productId, categoryId, mainCategory = 0) {
return __awaiter(this, void 0, void 0, function* () {
const fieldset = utils_1.toFieldset({ productId, categoryId, mainCategory });
return this.database.insert(`${this.table}_to_category`, fieldset);
});
}
toStore(productId, storeId) {
return __awaiter(this, void 0, void 0, function* () {
const criteria = utils_1.toFieldset({ productId, storeId });
return this.database.insert(`${this.table}_to_store`, criteria);
});
}
}
exports.default = ProductModel;