UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

136 lines (135 loc) 5.88 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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("../Category")); const ProductImage_1 = __importDefault(require("../ProductImage")); const class_validator_1 = require("class-validator"); const class_transformer_1 = require("class-transformer"); const Volume_1 = require("../Volume"); class BaseProduct { constructor(code, name, url, price, pricePerLiter, images, volume, mainCategory, subCategory, country, district, subDistrict, productSeelection, availability, buyable, status) { this.code = code; this.name = name; this.url = url; this.price = price; this.pricePerLiter = pricePerLiter; this.images = images; this.volume = volume; this.mainCategory = mainCategory; this.mainSubCategory = subCategory; this.mainCountry = country; this.district = district; this.subDistrict = subDistrict; this.productSelection = productSeelection; this.productAvailability = availability; this.buyable = buyable; this.status = status; } /** * Gets the populated version of the product. * @returns Promise<PopulatedProduct> */ populate() { return new Promise((resolve, reject) => { // Lazy require here because of circular dependencies Promise.resolve().then(() => __importStar(require("../../retrievers/getProduct"))).then((getProduct) => { const populatedProduct = getProduct.default(this.code); resolve(populatedProduct); }) .catch((e) => { reject(e); }); }); } } __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.IsString)() ], BaseProduct.prototype, "code", void 0); __decorate([ (0, class_validator_1.IsString)(), (0, class_validator_1.IsNotEmpty)() ], BaseProduct.prototype, "name", void 0); __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.IsString)() ], BaseProduct.prototype, "url", void 0); __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.IsNumber)() ], BaseProduct.prototype, "price", void 0); __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.IsNumber)() ], BaseProduct.prototype, "pricePerLiter", void 0); __decorate([ (0, class_validator_1.IsDefined)(), (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => ProductImage_1.default) ], BaseProduct.prototype, "images", void 0); __decorate([ (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => Volume_1.Volume) ], BaseProduct.prototype, "volume", void 0); __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => Category_1.default) ], BaseProduct.prototype, "mainCategory", void 0); __decorate([ (0, class_validator_1.IsOptional)(), (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => Category_1.default) ], BaseProduct.prototype, "mainSubCategory", void 0); __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => Category_1.default) ], BaseProduct.prototype, "mainCountry", void 0); __decorate([ (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => Category_1.default) ], BaseProduct.prototype, "district", void 0); __decorate([ (0, class_validator_1.ValidateNested)(), (0, class_transformer_1.Type)(() => Category_1.default) ], BaseProduct.prototype, "subDistrict", void 0); __decorate([ (0, class_validator_1.IsNotEmpty)(), (0, class_validator_1.IsString)() ], BaseProduct.prototype, "productSelection", void 0); __decorate([ (0, class_validator_1.IsBoolean)() ], BaseProduct.prototype, "buyable", void 0); exports.default = BaseProduct;