This commit is contained in:
seb
2026-10-11 03:30:26 +02:00
parent cf1c8d1126
commit 7ffb21aabb
5 changed files with 72 additions and 5 deletions

View File

@@ -3,6 +3,17 @@ SELECT
b.id,
b.name,
b.gsprpinfo,
(
SELECT COUNT(*)
FROM article a
LEFT JOIN article parent ON parent.id = a.parentarticle_id
WHERE a.company_id = b.company_id
AND a.is_parent = 0
AND NOT EXISTS (
SELECT 1 FROM article child WHERE child.parentarticle_id = a.id
)
AND COALESCE(parent.brand_id, a.brand_id) = b.id
) AS articleCount,
(
SELECT
p.hash AS fullHash,
@@ -31,6 +42,17 @@ SELECT
b.id,
b.name,
b.gsprpinfo,
(
SELECT COUNT(*)
FROM article a
LEFT JOIN article parent ON parent.id = a.parentarticle_id
WHERE a.company_id = b.company_id
AND a.is_parent = 0
AND NOT EXISTS (
SELECT 1 FROM article child WHERE child.parentarticle_id = a.id
)
AND COALESCE(parent.brand_id, a.brand_id) = b.id
) AS articleCount,
(
SELECT
p.hash AS fullHash,
@@ -54,6 +76,17 @@ SELECT
b.id,
b.name,
b.gsprpinfo,
(
SELECT COUNT(*)
FROM article a
LEFT JOIN article parent ON parent.id = a.parentarticle_id
WHERE a.company_id = b.company_id
AND a.is_parent = 0
AND NOT EXISTS (
SELECT 1 FROM article child WHERE child.parentarticle_id = a.id
)
AND COALESCE(parent.brand_id, a.brand_id) = b.id
) AS articleCount,
(
SELECT
p.hash AS fullHash,

View File

@@ -12,6 +12,17 @@ SELECT
b.id,
b.name,
b.gsprpinfo,
(
SELECT COUNT(*)
FROM article a
LEFT JOIN article parent ON parent.id = a.parentarticle_id
WHERE a.company_id = b.company_id
AND a.is_parent = 0
AND NOT EXISTS (
SELECT 1 FROM article child WHERE child.parentarticle_id = a.id
)
AND COALESCE(parent.brand_id, a.brand_id) = b.id
) AS articleCount,
(
SELECT COALESCE(json_group_array(json_object(
'fullHash', hash,
@@ -37,6 +48,17 @@ SELECT
b.id,
b.name,
b.gsprpinfo,
(
SELECT COUNT(*)
FROM article a
LEFT JOIN article parent ON parent.id = a.parentarticle_id
WHERE a.company_id = b.company_id
AND a.is_parent = 0
AND NOT EXISTS (
SELECT 1 FROM article child WHERE child.parentarticle_id = a.id
)
AND COALESCE(parent.brand_id, a.brand_id) = b.id
) AS articleCount,
(
SELECT COALESCE(json_group_array(json_object(
'fullHash', hash,
@@ -63,6 +85,17 @@ SELECT
b.id,
b.name,
b.gsprpinfo,
(
SELECT COUNT(*)
FROM article a
LEFT JOIN article parent ON parent.id = a.parentarticle_id
WHERE a.company_id = b.company_id
AND a.is_parent = 0
AND NOT EXISTS (
SELECT 1 FROM article child WHERE child.parentarticle_id = a.id
)
AND COALESCE(parent.brand_id, a.brand_id) = b.id
) AS articleCount,
(
SELECT COALESCE(json_group_array(json_object(
'fullHash', hash,

View File

@@ -48,11 +48,11 @@ export default function list(provider) {
* @param {number} [opts.limit=10] - Number of brands to return (max 100).
* @param {boolean} [opts.includeSmallThumbs=false] - Include 32px-edge small thumbnail dimensions and base64 AVIF data.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{brands: Array<{id: number, name: string, gsprpinfo: string|null, pics: Array<{fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW?: number|null, smallThumbH?: number|null, smallThumbBinary?: string|null}>}>, total: number, offset: number, limit: number}>} The brands plus the total unpaged count. Small-thumbnail fields are present only when `includeSmallThumbs` is true; the binary is base64-encoded AVIF data.
* @returns {Promise<{brands: Array<{id: number, name: string, articleCount: number, gsprpinfo: string|null, pics: Array<{fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW?: number|null, smallThumbH?: number|null, smallThumbBinary?: string|null}>}>, total: number, offset: number, limit: number}>} The brands plus the total unpaged count. Small-thumbnail fields are present only when `includeSmallThumbs` is true; the binary is base64-encoded AVIF data.
*
* @example
* const result = await store.brand.list(42, { offset: 0, limit: 10 });
* // => { brands: [{ id, name, gsprpinfo, pics: [...] }], total: 25, offset: 0, limit: 10 }
* // => { brands: [{ id, name, articleCount, gsprpinfo, pics: [...] }], total: 25, offset: 0, limit: 10 }
*/
return async (googleAuthId, opts, tx) => {
let offset = 0;
@@ -91,6 +91,7 @@ export default function list(provider) {
brands: listResult.rows.map((row) => ({
id: row.id,
name: row.name,
articleCount: Number(row.articleCount ?? 0),
gsprpinfo: row.gsprpinfo,
pics: parsePics(row.picsJson),
})),