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:
@@ -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 {
|
getProductFields(row: any): ProductFields {
|
||||||
if (!row.fields) {
|
if (!row.fields) {
|
||||||
return null; // 53460 for example
|
return null; // 53460 for example
|
||||||
@@ -118,6 +131,7 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
|
|
||||||
fields['artNo'] = fields['artNo'] ?? ''; // some actually exists without artNo
|
fields['artNo'] = fields['artNo'] ?? ''; // some actually exists without artNo
|
||||||
fields['name'] = fields['name'] ?? ''; // some actually exists without name
|
fields['name'] = fields['name'] ?? ''; // some actually exists without name
|
||||||
|
fields['localeNames'] = this.getLocaleNames(row);
|
||||||
fields['copyright'] = fields['copyright'] ?? '';
|
fields['copyright'] = fields['copyright'] ?? '';
|
||||||
fields['comments'] = fields['comments'] ?? '';
|
fields['comments'] = fields['comments'] ?? '';
|
||||||
fields['batch'] = fields['batch'] ?? '';
|
fields['batch'] = fields['batch'] ?? '';
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ SELECT products.productid AS id,
|
|||||||
JOIN "product-fields" fields ON fields.fieldid = pf.fieldid
|
JOIN "product-fields" fields ON fields.fieldid = pf.fieldid
|
||||||
WHERE pf.productid = products.productid
|
WHERE pf.productid = products.productid
|
||||||
) AS fields,
|
) 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)
|
SELECT json_agg(keywords.value)
|
||||||
FROM product_keyword pk
|
FROM product_keyword pk
|
||||||
|
|||||||
@@ -284,6 +284,7 @@ type Product {
|
|||||||
type ProductFields {
|
type ProductFields {
|
||||||
artNo: String!
|
artNo: String!
|
||||||
name: String!
|
name: String!
|
||||||
|
localeNames: JSON
|
||||||
height: Int
|
height: Int
|
||||||
width: Int
|
width: Int
|
||||||
photowallResolution: Int
|
photowallResolution: Int
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ export interface Product {
|
|||||||
export interface ProductFields {
|
export interface ProductFields {
|
||||||
artNo: string;
|
artNo: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
localeNames: Array<Record<string, string>>;
|
||||||
height?: number;
|
height?: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
photowallResolution?: number;
|
photowallResolution?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user