This commit is contained in:
seb
2026-09-30 21:12:32 +02:00
parent 69d172d49b
commit ed91ccbaee
3 changed files with 35 additions and 54 deletions

View File

@@ -139,10 +139,10 @@ SELECT
( (
SELECT SELECT
ap.sort, ap.sort,
p.hash, p.hash AS fullHash,
p.thumbhash, p.thumbhash AS thumbHash,
p.thumbw, p.thumbw AS thumbW,
p.thumbh p.thumbh AS thumbH
FROM articlepic ap FROM articlepic ap
INNER JOIN pic p ON p.id = ap.pic_id INNER JOIN pic p ON p.id = ap.pic_id
WHERE ap.article_id = a.id WHERE ap.article_id = a.id

View File

@@ -17,8 +17,8 @@ SELECT
t.rate AS priceTaxRate, a.id AS a_id, a.sku AS a_sku, t.rate AS priceTaxRate, a.id AS a_id, a.sku AS a_sku,
at.name AS a_name, at.slug AS a_slug, at.name AS a_name, at.slug AS a_slug,
(SELECT COALESCE(json_group_array(json_object( (SELECT COALESCE(json_group_array(json_object(
'sort', sort, 'hash', hash, 'thumbhash', thumbhash, 'sort', sort, 'fullHash', hash, 'thumbHash', thumbhash,
'thumbw', thumbw, 'thumbh', thumbh 'thumbW', thumbw, 'thumbH', thumbh
)), '[]') FROM ( )), '[]') FROM (
SELECT ap.sort, pic.hash, pic.thumbhash, pic.thumbw, pic.thumbh SELECT ap.sort, pic.hash, pic.thumbhash, pic.thumbw, pic.thumbh
FROM articlepic ap INNER JOIN pic ON pic.id = ap.pic_id FROM articlepic ap INNER JOIN pic ON pic.id = ap.pic_id

View File

@@ -20,13 +20,13 @@ export default function listByEntityAndSkus(provider) {
/** /**
* Lists article-supplier assignments for a given supplier (entityId) and SKU list, * Lists article-supplier assignments for a given supplier (entityId) and SKU list,
* including linked article details (name, slug, photos/articlepic, eans/articleean). * including linked article details (name, slug, photos, eans).
* *
* @param {number} googleAuthId - The id of the Google auth user. * @param {number} googleAuthId - The id of the Google auth user.
* @param {number|{entityId?: number, supplierId?: number, skus?: string[]|string}} entityIdOrOptions - The supplier entity id or an options object. * @param {number|{entityId?: number, supplierId?: number, skus?: string[]|string}} entityIdOrOptions - The supplier entity id or an options object.
* @param {string[]|string} [maybeSkus] - The list of SKUs to filter by (or single SKU string). * @param {string[]|string} [maybeSkus] - The list of SKUs to filter by (or single SKU string).
* @param {object} [tx] - Optional transaction. * @param {object} [tx] - Optional transaction.
* @returns {Promise<Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, priceId: number|null, price: {net: number, taxId: number, taxRate?: number}|null, article: {id: number, sku: string, name: string|null, slug: string|null, photos: Array<{sort: number, thumbhash: string, hash: string, thumbw: number, thumbh: number}>, articlepic: Array<{sort: number, thumbhash: string, hash: string, thumbw: number, thumbh: number}>, eans: string[], articleean: string[]}}>>} The supplier assignments with article details. * @returns {Promise<Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, priceId: number|null, price: {net: number, taxId: number, taxRate?: number}|null, article: {id: number, sku: string, name: string|null, slug: string|null, photos: Array<{sort: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[]}}>>} The supplier assignments with article details.
* @throws {Error} If user is not authorized, entityId is missing, or supplier does not exist. * @throws {Error} If user is not authorized, entityId is missing, or supplier does not exist.
* *
* @example * @example
@@ -84,23 +84,7 @@ export default function listByEntityAndSkus(provider) {
skusJson, skusJson,
}); });
return result.rows.map((row) => { return result.rows.map((row) => ({
const rawPhotos = parseJsonArray(row.photosJson);
const photos = rawPhotos.map((p) => ({
sort: p.sort,
thumbhash: p.thumbhash,
hash: p.hash,
thumbw: p.thumbw,
thumbh: p.thumbh,
thumbHash: p.thumbhash,
fullHash: p.hash,
thumbW: p.thumbw,
thumbH: p.thumbh,
}));
const eans = parseJsonArray(row.eansJson).map((r) => r.ean);
return {
id: row.id, id: row.id,
articleId: row.articleId, articleId: row.articleId,
entityId: row.entityId, entityId: row.entityId,
@@ -123,13 +107,10 @@ export default function listByEntityAndSkus(provider) {
sku: row.a_sku, sku: row.a_sku,
name: row.a_name ?? null, name: row.a_name ?? null,
slug: row.a_slug ?? null, slug: row.a_slug ?? null,
photos, photos: parseJsonArray(row.photosJson),
articlepic: photos, eans: parseJsonArray(row.eansJson).map((r) => r.ean),
eans,
articleean: eans,
}, },
}; }));
});
}; };
} }