P5 7619 refactor products to return list (#11)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ProductsFilter, ProductsFilterInput } from '../../types/product-types';
|
||||
import { Maybe } from '../../types/types';
|
||||
|
||||
// Get syntax highlighting with vscode by installing "Comment tagged templates2
|
||||
@@ -75,19 +76,17 @@ FROM "product-products" products
|
||||
LEFT JOIN "product-stockproducts" stock ON stock.productid = products.productid
|
||||
`;
|
||||
|
||||
export function products(
|
||||
limit: number = 100,
|
||||
visible: Maybe<boolean>,
|
||||
browsable: Maybe<boolean>,
|
||||
) {
|
||||
export function products(input: ProductsFilterInput) {
|
||||
const limit = input.pagination.limit ?? 100;
|
||||
const filter = input.filter;
|
||||
return (
|
||||
baseQuery +
|
||||
/* sql */ `
|
||||
${
|
||||
visible != null
|
||||
filter.visible != null
|
||||
? /* sql */ `
|
||||
WHERE products.visible = ${visible ? '1' : '0'}
|
||||
AND products.browsable = ${browsable ? '1' : '0'}`
|
||||
WHERE products.visible = ${filter?.visible ? '1' : '0'}
|
||||
AND products.browsable = ${filter?.browsable ? '1' : '0'}`
|
||||
: ``
|
||||
}
|
||||
LIMIT ${limit}
|
||||
@@ -95,6 +94,20 @@ LIMIT ${limit}
|
||||
);
|
||||
}
|
||||
|
||||
export function productsTotal(input: ProductsFilterInput) {
|
||||
const filter = input.filter;
|
||||
return /*sql */ `
|
||||
SELECT count(*) FROM "product-products" products
|
||||
${
|
||||
filter.visible != null
|
||||
? /* sql */ `
|
||||
WHERE products.visible = ${filter?.visible ? '1' : '0'}
|
||||
AND products.browsable = ${filter?.browsable ? '1' : '0'}`
|
||||
: ``
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
export function product(id: number) {
|
||||
return (
|
||||
baseQuery +
|
||||
|
||||
Reference in New Issue
Block a user