mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-03-25 09:25:51 +00:00
fix: Small adjustments
This commit is contained in:
parent
f1b5b7d36a
commit
7254acb946
4 changed files with 19 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
|
||||
const { normalizeCspc } = require("../utils/sku");
|
||||
const { normalizeSkuKey } = require("../utils/sku");
|
||||
const { humanBytes } = require("../utils/bytes");
|
||||
const { padLeft, padRight } = require("../utils/string");
|
||||
|
||||
|
|
@ -163,9 +163,8 @@ function productFromApi(p) {
|
|||
(Number.isFinite(p?.Price) ? `$${Number(p.Price).toFixed(2)}` : "");
|
||||
|
||||
const upc = String(p.UPC || "").trim();
|
||||
const sku =
|
||||
upc || // use UPC if present
|
||||
String(p.ProductStoreID); // fallback to store-specific ID
|
||||
const rawKey = upc || String(p.ProductStoreID || "").trim() || String(p.ProductID || "").trim();
|
||||
const sku = normalizeSkuKey(rawKey, { storeLabel: "Co-op World of Whisky", url });
|
||||
|
||||
const img = normalizeAbsUrl(p.ImageURL);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// src/tracker/merge.js
|
||||
"use strict";
|
||||
|
||||
const { normalizeCspc } = require("../utils/sku");
|
||||
const { normalizeSkuKey } = require("../utils/sku");
|
||||
const { normPrice } = require("../utils/price");
|
||||
|
||||
function normImg(v) {
|
||||
|
|
@ -15,10 +15,8 @@ function isRealSku(v) {
|
|||
return Boolean(normalizeCspc(v));
|
||||
}
|
||||
|
||||
function normalizeSkuPreserve(raw) {
|
||||
const s = String(raw || "").trim();
|
||||
const c = normalizeCspc(s);
|
||||
return c || s; // CSPC if present, else keep UPC/ProductStoreID/etc
|
||||
function normalizeSkuForDb(raw, { storeLabel, url } = {}) {
|
||||
return normalizeSkuKey(raw, { storeLabel, url });
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -108,7 +106,7 @@ function mergeDiscoveredIntoDb(prevDb, discovered) {
|
|||
if (!prev) {
|
||||
const now = {
|
||||
...nowRaw,
|
||||
sku: normalizeSkuPreserve(nowRaw.sku),
|
||||
sku: normalizeSkuForDb(nowRaw.sku, { storeLabel: nowRaw.storeLabel, url }),
|
||||
img: normImg(nowRaw.img),
|
||||
removed: false,
|
||||
};
|
||||
|
|
@ -121,7 +119,7 @@ function mergeDiscoveredIntoDb(prevDb, discovered) {
|
|||
if (prevUrlForThisItem === url && prev.removed) {
|
||||
const now = {
|
||||
...nowRaw,
|
||||
sku: normalizeSkuPreserve(nowRaw.sku) || normalizeSkuPreserve(prev.sku),
|
||||
sku: normalizeSkuForDb(nowRaw.sku, { storeLabel: nowRaw.storeLabel, url }) || normalizeSkuForDb(prev.sku, { storeLabel: prev.storeLabel, url: prev.url }),
|
||||
img: normImg(nowRaw.img) || normImg(prev.img),
|
||||
removed: false,
|
||||
};
|
||||
|
|
@ -139,8 +137,8 @@ function mergeDiscoveredIntoDb(prevDb, discovered) {
|
|||
const prevPrice = normPrice(prev.price);
|
||||
const nowPrice = normPrice(nowRaw.price);
|
||||
|
||||
const prevSku = normalizeSkuPreserve(prev.sku);
|
||||
const nowSku = normalizeSkuPreserve(nowRaw.sku) || prevSku;
|
||||
const prevSku = normalizeSkuForDb(prev.sku, { storeLabel: prev.storeLabel, url: prev.url });
|
||||
const nowSku = normalizeSkuForDb(nowRaw.sku, { storeLabel: nowRaw.storeLabel, url }) || prevSku;
|
||||
|
||||
const prevImg = normImg(prev.img);
|
||||
let nowImg = normImg(nowRaw.img);
|
||||
|
|
|
|||
|
|
@ -56,8 +56,9 @@ function isNumericSku(k) {
|
|||
}
|
||||
|
||||
function isUpcSku(k) {
|
||||
// UPC-A/EAN/GTIN-ish (most common: 12 or 13; sometimes 14)
|
||||
return /^\d{12,14}$/.test(String(k || "").trim());
|
||||
const s = String(k || "").trim();
|
||||
if (s.startsWith("upc:")) return true;
|
||||
return /^\d{12,14}$/.test(s); // keep legacy support
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -233,8 +233,9 @@ function isSoftSkuKey(k) {
|
|||
|
||||
|
||||
function isUpcSkuKey(k) {
|
||||
return /^\d{12,14}$/.test(String(k || "").trim());
|
||||
}
|
||||
const s = String(k || "").trim();
|
||||
return s.startsWith("upc:") || /^\d{12,14}$/.test(s);
|
||||
}
|
||||
|
||||
|
||||
function isABStoreLabel(label) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue