You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
const createDatasheet = require("../../shared/create-datasheet");
|
|
|
|
function isEnglish(document) {
|
|
return /\sen\s*$/.test(document.description);
|
|
}
|
|
|
|
module.exports = function tmeNormalizeProduct() {
|
|
return async function (api) {
|
|
let { data } = api;
|
|
|
|
if (data.itemData.documents.length > 0) {
|
|
if (typeof data.itemData.documents[0] === "string") {
|
|
// Temporary workaround for the dependsOn not taking into account task versions, and some old records existing with a wrong documents structure
|
|
return;
|
|
}
|
|
|
|
let manufacturer = data.itemData.manufacturer;
|
|
let modelName = data.itemData.model;
|
|
let description = data.itemData.description;
|
|
let productID = data.itemData.productID;
|
|
|
|
let firstEnglish = data.itemData.documents.find((document) => isEnglish(document));
|
|
|
|
let bestDocument = (firstEnglish != null)
|
|
? firstEnglish
|
|
: data.itemData.documents[0];
|
|
|
|
let bestDocumentIsEnglish = isEnglish(bestDocument);
|
|
|
|
createDatasheet(api, {
|
|
priority: (bestDocumentIsEnglish)
|
|
? 0.6
|
|
: 0.5,
|
|
source: "tme",
|
|
manufacturer: manufacturer,
|
|
productID: productID,
|
|
name: modelName,
|
|
description: description,
|
|
url: bestDocument.url
|
|
});
|
|
}
|
|
};
|
|
};
|