Add category locale names (#112)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user