Add embryo to products
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
// Get syntax highlighting with vscode by installing "Comment tagged templates2
|
||||
|
||||
export function products(
|
||||
visible: boolean | null,
|
||||
browsable: boolean | null,
|
||||
limit: number = 100,
|
||||
) {
|
||||
const query = /* sql */ `
|
||||
SELECT products.productid,
|
||||
products.path,
|
||||
products.visible,
|
||||
products.browsable,
|
||||
products.designerid,
|
||||
products.inserted,
|
||||
products.updated,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'printid',
|
||||
printproducts.printid,
|
||||
'productid',
|
||||
printproducts.productid,
|
||||
'groupid',
|
||||
printproducts.groupid,
|
||||
'inserted',
|
||||
printproducts.inserted,
|
||||
'updated',
|
||||
printproducts.updated
|
||||
)
|
||||
) AS print_products,
|
||||
json_agg(
|
||||
json_build_object(
|
||||
'id',
|
||||
blacklist.id,
|
||||
'product_id',
|
||||
blacklist.product_id,
|
||||
'market_id',
|
||||
blacklist.market_id,
|
||||
'group_id',
|
||||
blacklist.group_id,
|
||||
'created_at',
|
||||
blacklist.created_at,
|
||||
'updated_at',
|
||||
blacklist.updated_at
|
||||
)
|
||||
) AS blacklisted
|
||||
FROM "product-products" products
|
||||
JOIN "product-printproducts" printproducts ON products.productid = printproducts.productid
|
||||
JOIN product_blacklist blacklist ON products.productid = blacklist.product_id
|
||||
${
|
||||
visible != null
|
||||
? /* sql */ `
|
||||
WHERE products.visible = ${visible ? '1' : '0'}
|
||||
AND products.browsable = ${browsable ? '1' : '0'}`
|
||||
: ``
|
||||
}
|
||||
|
||||
GROUP BY products.productid
|
||||
LIMIT ${limit}
|
||||
`;
|
||||
|
||||
return query;
|
||||
}
|
||||
Reference in New Issue
Block a user