Add Query for productByPath (#117)
This commit is contained in:
@@ -194,6 +194,18 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
return res.find(Boolean);
|
return res.find(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getProductByPath(path: string): Promise<Maybe<Product>> {
|
||||||
|
const query = sql.productByPath(path);
|
||||||
|
|
||||||
|
const res = await this.knex.raw(query).then((data) =>
|
||||||
|
data.rows.map((row) => {
|
||||||
|
const prod = this.createProductFromRow(row);
|
||||||
|
return prod;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return res.find(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
async getDesignerProducts(designerId: number): Promise<Array<Product>> {
|
async getDesignerProducts(designerId: number): Promise<Array<Product>> {
|
||||||
const query = sql.designerProducts();
|
const query = sql.designerProducts();
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,15 @@ export function product(id: number) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function productByPath(path: string) {
|
||||||
|
return (
|
||||||
|
baseQuery +
|
||||||
|
/* sql */ `
|
||||||
|
WHERE products.path = '${path}'
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function categoryProducts(categoryId: number) {
|
export function categoryProducts(categoryId: number) {
|
||||||
return (
|
return (
|
||||||
baseQuery +
|
baseQuery +
|
||||||
|
|||||||
@@ -121,6 +121,14 @@ async function getProduct(_, { id }, { dataSources, auth }): Promise<Product> {
|
|||||||
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
return (<ProductAPI>dataSources.productApi).getProduct(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getProductByPath(
|
||||||
|
_,
|
||||||
|
{ path },
|
||||||
|
{ dataSources },
|
||||||
|
): Promise<Product> {
|
||||||
|
return (<ProductAPI>dataSources.productApi).getProductByPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
export const productTypeDefs = {
|
export const productTypeDefs = {
|
||||||
ProductBlacklist,
|
ProductBlacklist,
|
||||||
Product,
|
Product,
|
||||||
@@ -130,6 +138,7 @@ export const productTypeDefs = {
|
|||||||
export const productQueryTypeDefs = {
|
export const productQueryTypeDefs = {
|
||||||
products: getProductsResult,
|
products: getProductsResult,
|
||||||
product: getProduct,
|
product: getProduct,
|
||||||
|
productByPath: getProductByPath,
|
||||||
productsSearch: getProductsSearchResult,
|
productsSearch: getProductsSearchResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Query {
|
|||||||
filter: ProductsFilterInput
|
filter: ProductsFilterInput
|
||||||
): ProductsResult
|
): ProductsResult
|
||||||
product(id: Int!): Product
|
product(id: Int!): Product
|
||||||
|
productByPath(path: String!): Product
|
||||||
productsSearch(q: String!): ProductsSearchResult
|
productsSearch(q: String!): ProductsSearchResult
|
||||||
categories: [Category]
|
categories: [Category]
|
||||||
category(id: Int!): Category
|
category(id: Int!): Category
|
||||||
|
|||||||
Reference in New Issue
Block a user