UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

29 lines (28 loc) 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("../constants"); const ProductRelease_1 = __importDefault(require("../models/ProductRelease")); const GET_1 = require("../util/GET"); function getAbsoluteURL(path) { return path.startsWith("/") ? "www.vinmonopolet.no" + path : "www.vinmonopolet.no/" + path; } function tryToGetReleaseDate(title) { const splitTitle = title.split(":"); if (splitTitle.length < 2) { return undefined; } return splitTitle[0]; } function toProductRelease(dto) { return new ProductRelease_1.default(dto.title, dto.primaryCategoryName, getAbsoluteURL(dto.label), getAbsoluteURL(dto.listImageUrl), tryToGetReleaseDate(dto.title)); } async function getProductReleases() { const { contentSearchResult } = await (0, GET_1.GET)(constants_1.VINMONOPOLET_SEARCH_URL, new URLSearchParams({ categoryCode: "lanseringer" })); return contentSearchResult.results.map(toProductRelease); } exports.default = getProductReleases;