u
This commit is contained in:
@@ -99,13 +99,13 @@ Lists the brands of the user's selected company, sorted by name.
|
||||
|
||||
**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.
|
||||
`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**
|
||||
|
||||
```js
|
||||
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 }
|
||||
```
|
||||
|
||||
## `brand.update`
|
||||
|
||||
2
API.md
2
API.md
@@ -132,7 +132,7 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
|
||||
- `addImage(googleAuthId: number, brandId: number, image: Buffer, tx?: object): Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array<object>}>`
|
||||
- `create(googleAuthId: number, input: {name: string, gsprpinfo?: string}, tx?: object): Promise<{id: number, name: string, gsprpinfo: string|null, pics: Array<{fullHash: string, thumbW: number, thumbH: number, thumbHash: string}>}>`
|
||||
- `delete(googleAuthId: number, id: number, tx?: object): Promise<void>`
|
||||
- `list(googleAuthId: number, opts?: {offset?: number, limit?: number, includeSmallThumbs?: boolean}, tx?: object): 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}>`
|
||||
- `list(googleAuthId: number, opts?: {offset?: number, limit?: number, includeSmallThumbs?: boolean}, tx?: object): 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}>`
|
||||
- `update(googleAuthId: number, id: number, input: {name?: string, gsprpinfo?: string}, tx?: object): Promise<{id: number, name: string, gsprpinfo: string|null, touchedArticleCount: number}>`
|
||||
- `upsert(googleAuthId: number, input: {name: string, gsprpinfo?: string}, tx?: object): Promise<{id: number, name: string, gsprpinfo: string|null, pics: Array<{fullHash: string, thumbW: number, thumbH: number, thumbHash: string}>}>`
|
||||
- [customergroup](API.customergroup.md)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
})),
|
||||
|
||||
Reference in New Issue
Block a user