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 { Category } from '../types/category-types';
|
||||||
|
import { BaseSQLDataSource } from './BaseSQLDataSource';
|
||||||
|
|
||||||
const MINUTE = 60;
|
const MINUTE = 60;
|
||||||
|
|
||||||
export class CategoryAPI extends SQLDataSource {
|
export class CategoryAPI extends BaseSQLDataSource {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,20 @@ WHERE product_category.product_id = ?
|
|||||||
.cache(MINUTE);
|
.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?
|
* TODO: should we have these?
|
||||||
* category keywords
|
* category keywords
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ const Category = {
|
|||||||
return (<ProductAPI>dataSources.productApi).getCategoryProducts(id);
|
return (<ProductAPI>dataSources.productApi).getCategoryProducts(id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async localeNames({ id }, _, { dataSources, auth }) {
|
||||||
|
return (<CategoryAPI>dataSources.categoryApi).getLocaleNameForId(id);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getCategories(_, _args, { dataSources }) {
|
async function getCategories(_, _args, { dataSources }) {
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ type Category {
|
|||||||
Default to false
|
Default to false
|
||||||
"""
|
"""
|
||||||
products(includeAllSubCategories: Boolean): [Product]
|
products(includeAllSubCategories: Boolean): [Product]
|
||||||
|
localeNames: JSON
|
||||||
}
|
}
|
||||||
|
|
||||||
type Batch {
|
type Batch {
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ export interface Category {
|
|||||||
childCount: number;
|
childCount: number;
|
||||||
lft: number;
|
lft: number;
|
||||||
rgt: number;
|
rgt: number;
|
||||||
|
localeNames: Array<Record<string, string>>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user