added localized names to product output (#173)

* added localized names to product output

* changed to localeNames to conform with other localeNames
This commit is contained in:
Arwid Thornström
2025-05-15 10:10:27 +02:00
committed by GitHub
parent 10fa25b230
commit c08787422f
4 changed files with 28 additions and 0 deletions
+14
View File
@@ -106,6 +106,19 @@ export class ProductAPI extends BaseSQLDataSource {
});
}
getLocaleNames(row: any): Record<string, string> {
if (!row.localizednames) {
return {};
}
return row.localizednames.reduce(
(result: Record<string, string>, ln: any) => {
result[ln.locale_name] = ln.name;
return result;
},
{},
);
}
getProductFields(row: any): ProductFields {
if (!row.fields) {
return null; // 53460 for example
@@ -118,6 +131,7 @@ export class ProductAPI extends BaseSQLDataSource {
fields['artNo'] = fields['artNo'] ?? ''; // some actually exists without artNo
fields['name'] = fields['name'] ?? ''; // some actually exists without name
fields['localeNames'] = this.getLocaleNames(row);
fields['copyright'] = fields['copyright'] ?? '';
fields['comments'] = fields['comments'] ?? '';
fields['batch'] = fields['batch'] ?? '';
+12
View File
@@ -62,6 +62,18 @@ SELECT products.productid AS id,
JOIN "product-fields" fields ON fields.fieldid = pf.fieldid
WHERE pf.productid = products.productid
) AS fields,
(
SELECT json_agg(
json_build_object(
'name', td.text,
'locale_id', td.locale_id,
'locale_name', l.value
)
) AS result FROM public."i18n-texts" t
JOIN "i18n-texts_data" td ON t.textid = td.textid
JOIN locales l ON td.locale_id = l.id
WHERE t.name = CAST(products.productid AS text)
) AS localizednames,
(
SELECT json_agg(keywords.value)
FROM product_keyword pk
+1
View File
@@ -284,6 +284,7 @@ type Product {
type ProductFields {
artNo: String!
name: String!
localeNames: JSON
height: Int
width: Int
photowallResolution: Int
+1
View File
@@ -159,6 +159,7 @@ export interface Product {
export interface ProductFields {
artNo: string;
name: string;
localeNames: Array<Record<string, string>>;
height?: number;
width?: number;
photowallResolution?: number;