Added products

This commit is contained in:
Niklas Fondberg
2021-04-07 16:06:55 +02:00
parent 949c641410
commit 59e385c144
6 changed files with 163 additions and 56 deletions
+40 -39
View File
@@ -6,46 +6,48 @@ export function products(
limit: number = 100,
) {
const query = /* sql */ `
SELECT products.productid,
products.path,
products.visible,
products.browsable,
products.designerid,
products.inserted,
products.updated,
json_agg(
SELECT products.productid as id,
products.path,
products.visible,
products.browsable,
products.designerid,
products.inserted,
products.updated,
(
SELECT 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(
'printId',
"product-printproducts".printid,
'productId',
"product-printproducts".productid,
'groupId',
"product-printproducts".groupid,
'inserted',
"product-printproducts".inserted,
'updated',
"product-printproducts".updated
)
) FROM "product-printproducts" WHERE "product-printproducts".productid = products.productid
) AS printProducts,
( SELECT 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
'id',
product_blacklist.id,
'productId',
product_blacklist.product_id,
'marketId',
product_blacklist.market_id,
'groupId',
product_blacklist.group_id,
'inserted',
product_blacklist.created_at,
'updated',
product_blacklist.updated_at
)
) FROM product_blacklist WHERE product_blacklist.product_id = products.productid
) AS blacklisting
FROM "product-products" products
${
visible != null
? /* sql */ `
@@ -53,7 +55,6 @@ FROM "product-products" products
AND products.browsable = ${browsable ? '1' : '0'}`
: ``
}
GROUP BY products.productid
LIMIT ${limit}
`;