From 813e7c89b890cf6fdbcedd296ad766ea1a1e5338 Mon Sep 17 00:00:00 2001 From: seb Date: Tue, 20 Oct 2026 23:16:47 +0200 Subject: [PATCH] u --- API.category.md | 2 +- API.md | 2 +- src/providers/mssql/queries/article.js | 3 +++ src/store/category/getCategoryArticles.js | 2 +- src/store/category/queryCategoryArticles.js | 7 +++++++ test/category.test.js | 11 +++++++++++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/API.category.md b/API.category.md index b6c4f7a..7be08f9 100644 --- a/API.category.md +++ b/API.category.md @@ -158,7 +158,7 @@ Returns the articles belonging to a single category. **Returns** -`Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>` — The articles in the category. +`Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>` — The articles in the category. **Example** diff --git a/API.md b/API.md index 97ba492..e5831d1 100644 --- a/API.md +++ b/API.md @@ -99,7 +99,7 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met - `delete(input: {googleAuthId: number, id: number, recursive?: boolean}, tx?: object): Promise` - `deleteImage(googleAuthId: number, categoryId: number, tx?: object): Promise<{id: number, thumbW: null, thumbH: null, thumbHash: null}>` - `ensureByPath(input: {googleAuthId: number, parentId: number, path: string}, tx?: object): Promise` - - `getCategoryArticles(googleAuthId: number, categoryId: number, tx?: object): Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>` + - `getCategoryArticles(googleAuthId: number, categoryId: number, tx?: object): Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>` - `getTreeForCompany(googleAuthId: number, tx?: object): Promise<{languageId: number, tree: Array<{id: number, parentId: number|null, sort: number, name: string|null, slug: string|null, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null, articleCount: number, posterminalIds: number[]}>, articleCount: number}>` - `move(input: {googleAuthId: number, id: number, parentId: number}, tx?: object): Promise<{id: number, parentId: number, sort: number}>` - `order(input: {googleAuthId: number, parentId: number, categoryIds: Array}, tx?: object): Promise<{categoryIds: Array}>` diff --git a/src/providers/mssql/queries/article.js b/src/providers/mssql/queries/article.js index db5ee34..a8bb969 100644 --- a/src/providers/mssql/queries/article.js +++ b/src/providers/mssql/queries/article.js @@ -60,6 +60,9 @@ export const ARTICLE_LIST_COLUMNS = ` pic.thumbw AS thumbW, pic.thumbh AS thumbH, pic.thumbhash AS thumbHash, + pic.smallthumbw AS smallThumbW, + pic.smallthumbh AS smallThumbH, + pic.smallthumbbinary AS smallThumbBinary, b.id AS brandId, b.name AS brandName, brand_pic.hash AS brandFullHash, diff --git a/src/store/category/getCategoryArticles.js b/src/store/category/getCategoryArticles.js index cb67451..876c4d7 100644 --- a/src/store/category/getCategoryArticles.js +++ b/src/store/category/getCategoryArticles.js @@ -11,7 +11,7 @@ export default function getCategoryArticles(provider) { * @param {number} googleAuthId - The id of the Google auth user. * @param {number} categoryId - The id of the category. * @param {object} [tx] - Optional transaction to run within. - * @returns {Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>} The articles in the category. + * @returns {Promise, warehouses: Array<{id: number, name: string, stock: number}>}>>} The articles in the category. * * @example * const articles = await store.category.getCategoryArticles(42, 5); diff --git a/src/store/category/queryCategoryArticles.js b/src/store/category/queryCategoryArticles.js index 4b6f46b..ed8e063 100644 --- a/src/store/category/queryCategoryArticles.js +++ b/src/store/category/queryCategoryArticles.js @@ -56,6 +56,13 @@ export default function queryCategoryArticles(provider) { const summaries = summaryMap.get(row.id) ?? []; return { ...rest, + smallThumbW: rest.smallThumbW != null ? Number(rest.smallThumbW) : null, + smallThumbH: rest.smallThumbH != null ? Number(rest.smallThumbH) : null, + smallThumbBinary: rest.smallThumbBinary + ? (Buffer.isBuffer(rest.smallThumbBinary) + ? rest.smallThumbBinary.toString('base64') + : String(rest.smallThumbBinary)) + : null, track_stock: Boolean(rest.track_stock ?? 0), // MSSQL returns BIT as boolean, SQLite as 0/1 integer. Normalize so both // dialects expose isParent as a real boolean, matching article/getBySku. diff --git a/test/category.test.js b/test/category.test.js index 5af522d..4a10012 100644 --- a/test/category.test.js +++ b/test/category.test.js @@ -90,8 +90,19 @@ describe('store.category', () => { assert.equal(list[0].sku, art.sku); assert.equal(list[0].name, 'Listed'); assert.equal(list[0].parentArticleId, null); + assert.equal(list[0].smallThumbW, null); + assert.equal(list[0].smallThumbH, null); + assert.equal(list[0].smallThumbBinary, null); assert(Array.isArray(list[0].articlewarehousesummary)); assert(Array.isArray(list[0].warehouses)); + + await store.article.addImage(tenant.googleAuthId, art.sku, await makePng()); + const listWithImg = await store.category.getCategoryArticles(tenant.googleAuthId, cat.id); + assert.equal(listWithImg.length, 1); + assert.ok(listWithImg[0].smallThumbW > 0); + assert.ok(listWithImg[0].smallThumbH > 0); + assert.equal(typeof listWithImg[0].smallThumbBinary, 'string'); + assert.ok(listWithImg[0].smallThumbBinary.length > 0); }); it('rejects a category of another company', async () => {