UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

175 lines (174 loc) 5.33 kB
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; }; import Category from "../Category"; import ProductImage from "../ProductImage"; import { IsBoolean, IsDefined, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested, } from "class-validator"; import { Type } from "class-transformer"; import { Volume } from "../Volume"; class BaseProduct { /** * Unique ID for the product. */ code; /** * The product name */ name; /** * The url to the vinmonopol.no product page */ url; /** * The product price */ price; /** * The product price per liter */ pricePerLiter; /** * An array of product images */ images; /** * The volume of the product. */ volume; // Classification /** * The main category of the product (Øl, mjød, hvitvin etc..) */ mainCategory; /** * The sub category of the product (Porter & Stout, Rom, India Pale Ale etc..). */ mainSubCategory; /** * The country of origin. */ mainCountry; /** * The district the product is from. Might not always have values if no district is given. */ district; /** * The sub-district the product is from. Might not always have values if no sub-district is given. */ subDistrict; /** * The given product selection the product is available in (Bestillingsutvalget, Basisutvalget etc). */ productSelection; // Stock/store-related /** * information regarding the product availability either in stores or through mail. */ productAvailability; /** * A boolean representing if the product is currently buyable. */ buyable; /** * The status of the product. Most commonly just "active". */ status; 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 import("../../retrievers/getProduct") .then((getProduct) => { const populatedProduct = getProduct.default(this.code); resolve(populatedProduct); }) .catch((e) => { reject(e); }); }); } } __decorate([ IsNotEmpty(), IsString() ], BaseProduct.prototype, "code", void 0); __decorate([ IsString(), IsNotEmpty() ], BaseProduct.prototype, "name", void 0); __decorate([ IsNotEmpty(), IsString() ], BaseProduct.prototype, "url", void 0); __decorate([ IsNotEmpty(), IsNumber() ], BaseProduct.prototype, "price", void 0); __decorate([ IsNotEmpty(), IsNumber() ], BaseProduct.prototype, "pricePerLiter", void 0); __decorate([ IsDefined(), ValidateNested(), Type(() => ProductImage) ], BaseProduct.prototype, "images", void 0); __decorate([ ValidateNested(), Type(() => Volume) ], BaseProduct.prototype, "volume", void 0); __decorate([ IsNotEmpty(), ValidateNested(), Type(() => Category) ], BaseProduct.prototype, "mainCategory", void 0); __decorate([ IsOptional(), ValidateNested(), Type(() => Category) ], BaseProduct.prototype, "mainSubCategory", void 0); __decorate([ IsNotEmpty(), ValidateNested(), Type(() => Category) ], BaseProduct.prototype, "mainCountry", void 0); __decorate([ ValidateNested(), Type(() => Category) ], BaseProduct.prototype, "district", void 0); __decorate([ ValidateNested(), Type(() => Category) ], BaseProduct.prototype, "subDistrict", void 0); __decorate([ IsNotEmpty(), IsString() ], BaseProduct.prototype, "productSelection", void 0); __decorate([ IsBoolean() ], BaseProduct.prototype, "buyable", void 0); export default BaseProduct;