UNPKG

opencart-manager

Version:

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

76 lines (75 loc) 3.55 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 errors_1 = __importDefault(require("../errors")); const utils_1 = require("../utils"); class ProductOptionValue { constructor(model, productOptionId, optionValueId, _id) { this.model = model; this.productOptionId = productOptionId; this.optionValueId = optionValueId; this._id = _id; this.data = {}; } get id() { return this._id; } setData(newData) { this.data = Object.assign(Object.assign({}, this.data), newData); return this; } insert() { return __awaiter(this, void 0, void 0, function* () { if (utils_1.isInteger(this._id)) throw new Error(errors_1.default.ENTITY_INSERTED); const { productId } = (yield this.model.product.option.select({ productOptionId: this.productOptionId, }))[0]; const { optionId } = (yield this.model.option.value.select({ optionValueId: this.optionValueId, }))[0]; const { insertId } = yield this.model.product.option.value.insert(Object.assign(Object.assign({}, this.data), { productOptionId: this.productOptionId, productId, optionId, optionValueId: this.optionValueId })); this._id = insertId; return this; }); } update() { return __awaiter(this, void 0, void 0, function* () { if (!utils_1.isInteger(this._id)) throw new Error(errors_1.default.ENTITY_NOT_INSERTED); const { productId } = (yield this.model.product.option.select({ productOptionId: this.productOptionId, }))[0]; const { optionId } = (yield this.model.option.value.select({ optionValueId: this.optionValueId, }))[0]; yield this.model.product.option.value.update({ productOptionValueId: this._id }, Object.assign(Object.assign({}, this.data), { productOptionValueId: this._id, productOptionId: this.productOptionId, productId, optionId, optionValueId: this.optionValueId })); return this; }); } delete() { return __awaiter(this, void 0, void 0, function* () { if (!utils_1.isInteger(this._id)) throw new Error(errors_1.default.ENTITY_NOT_INSERTED); yield this.model.product.option.value.delete({ productOptionValueId: this._id, }); this._id = undefined; return this; }); } } exports.default = ProductOptionValue;