2023-05-25 13:54:28 +02:00
|
|
|
const axios = require("axios");
|
2023-05-28 19:48:06 +02:00
|
|
|
const utils = require("./utils");
|
2023-05-25 13:54:28 +02:00
|
|
|
|
2023-05-27 22:27:09 +02:00
|
|
|
const conversions = {
|
|
|
|
'CM': { unit: 'cm', factor: 1 },
|
|
|
|
'DAG': { unit: 'g', factor: 10 },
|
|
|
|
'DL': { unit: 'ml', factor: 10 },
|
|
|
|
'GRM': { unit: 'g', factor: 1 },
|
|
|
|
'H87': { unit: 'ml', factor: 1000 },
|
|
|
|
'HLT': { unit: 'ml', factor: 1000 },
|
|
|
|
'KGM': { unit: 'g', factor: 1000 },
|
|
|
|
'LTR': { unit: 'ml', factor: 1000 },
|
|
|
|
'MLT': { unit: 'ml', factor: 1 },
|
|
|
|
'MTR': { unit: 'm', factor: 1 },
|
|
|
|
'XRO': { unit: 'stk', factor: 1 },
|
|
|
|
};
|
|
|
|
|
2023-05-25 13:54:28 +02:00
|
|
|
exports.getCanonical = function(item, today) {
|
2023-05-27 22:27:09 +02:00
|
|
|
let quantity = item.prices[0].presentationPrice.measurementUnit.quantity
|
|
|
|
let unit = item.prices[0].presentationPrice.measurementUnit.unitCode
|
2023-05-28 18:30:02 +02:00
|
|
|
const isWeighted = (item.mixins.productCustomAttributes?.packagingDescription ?? "").startsWith("Gewichtsware");
|
2023-05-28 19:48:06 +02:00
|
|
|
return utils.convertUnit({
|
2023-05-25 13:54:28 +02:00
|
|
|
id: item.code,
|
2023-05-28 19:10:08 +02:00
|
|
|
name: item.name[0],
|
2023-05-28 18:30:02 +02:00
|
|
|
isWeighted,
|
|
|
|
price: isWeighted ? item.prices[0].effectiveAmount : item.prices[0].presentationPrice.effectiveAmount,
|
2023-05-25 13:54:28 +02:00
|
|
|
priceHistory: [{ date: today, price: item.prices[0].presentationPrice.effectiveAmount }],
|
2023-05-27 22:27:09 +02:00
|
|
|
unit,
|
|
|
|
quantity,
|
2023-05-26 18:12:29 +02:00
|
|
|
bio: item.mixins.mpreisAttributes.properties?.includes('BIO'),
|
2023-05-28 22:31:12 +02:00
|
|
|
url: `https://www.mpreis.at/shop/p/${item.code}`,
|
2023-05-28 19:48:06 +02:00
|
|
|
}, conversions, 'mpreis');
|
2023-05-25 13:54:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetchData = async function() {
|
|
|
|
const MPREIS_URL = `https://ax2ixv4hll-dsn.algolia.net/1/indexes/prod_mpreis_8450/browse?X-Algolia-API-Key=NmJlMTI0NjY1NGU4MDUwYTRlMmYzYWFjOWFlY2U4MGFkNGZjMDY2NmNjNjQzNWY3OWJlNDY4OTY0ZjEwOTEwYWZpbHRlcnM9cHVibGlzaGVk&X-Algolia-Application-Id=AX2IXV4HLL&X-Algolia-Agent=Vue.js`
|
|
|
|
let mpreisItems = [];
|
|
|
|
let res = (await axios.get(MPREIS_URL)).data;
|
|
|
|
mpreisItems = mpreisItems.concat(res.hits);
|
|
|
|
cursor = res.cursor;
|
|
|
|
while (cursor) {
|
|
|
|
res = (await axios.get(MPREIS_URL + `&cursor=${cursor}`)).data;
|
|
|
|
mpreisItems = mpreisItems.concat(res.hits);
|
|
|
|
cursor = res.cursor;
|
|
|
|
}
|
|
|
|
return mpreisItems;
|
2023-05-28 22:31:12 +02:00
|
|
|
}
|