Add category locale names (#112)

This commit is contained in:
Niklas Fondberg
2022-04-21 11:59:35 +02:00
committed by GitHub
parent 60d4d312f1
commit 9e2ff31b65
4 changed files with 21 additions and 2 deletions
+16 -2
View File
@@ -1,9 +1,9 @@
import { SQLDataSource } from 'datasource-sql';
import { Category } from '../types/category-types';
import { BaseSQLDataSource } from './BaseSQLDataSource';
const MINUTE = 60;
export class CategoryAPI extends SQLDataSource {
export class CategoryAPI extends BaseSQLDataSource {
constructor(config) {
super(config);
}
@@ -48,6 +48,20 @@ WHERE product_category.product_id = ?
.cache(MINUTE);
}
async getLocaleNameForId(id: number): Promise<JSON> {
const res = await this.cachedRaw(
`
SELECT json_object_agg(ec.locale, ec.name) as locale_names
FROM v_esales_categorytree_i18n ec
WHERE ec.id = ${id}
`,
)
.cache(MINUTE * 5)
.then((data) => data.rows);
return res[0].locale_names;
}
/**
* TODO: should we have these?
* category keywords