vinmonopolet-ts
Version:
Extracts information on products, categories and stores from Vinmonopolet
24 lines (23 loc) • 945 B
JavaScript
import { VINMONOPOLET_SEARCH_URL } from "../constants";
import ProductRelease from "../models/ProductRelease";
import { GET } from "../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(dto.title, dto.primaryCategoryName, getAbsoluteURL(dto.label), getAbsoluteURL(dto.listImageUrl), tryToGetReleaseDate(dto.title));
}
async function getProductReleases() {
const { contentSearchResult } = await GET(VINMONOPOLET_SEARCH_URL, new URLSearchParams({ categoryCode: "lanseringer" }));
return contentSearchResult.results.map(toProductRelease);
}
export default getProductReleases;