BUCBGGRUTH7HNAADSU24U4BPHPUY7QYB3KRZPIIDUERZTL3YNTZQC
2WDAUGOPI2S5H2B6VA3NHUICB4JUJGVD6L5O7VXNXD45SSRDCSFQC
ZI2RJOZ2HXBHX7L54BTSDKESY6NG5KBJLVHCNY7K7ZLGIUOIHQUQC
E4HFJ4L4PAGV7R7EXVG2B2CWDGGW7XWU4D37VURZ66HZ3ILHCFUAC
EDVJECDIUUOSU4TS2DCL25MJDR5RQG7PQVTYEM6R3B4SFGKSX6MAC
WYTMZJFYVKHR4QH7AV5JUNWXT6NAC5NNQNPZCQSDI6LGI7DVXFYAC
UCY5PVFCT2QIOGR47KFS4KBF2ZPHRBOAIOH6PJEVWCHLMBRBLOMQC
5FCMFAPUTCCO2JILRWLC4PHOSHYFCQNH3D7PKLA267MHVZADOX2AC
CBD_min decimal(6, 4) not null,
CBD_max decimal(6, 4) not null,
THC_min decimal(6, 4) not null,
THC_max decimal(6, 4) not null,
price decimal(5, 2) not null,
stock smallint not null,
CBD numrange not null check (lower(CBD) >= 0),
THC numrange not null check (lower(THC) >= 0),
price decimal(5, 2) not null check (price >= 0),
stock smallint not null check (stock >= 0),
COALESCE(json_agg(json_build_object('id', variant.id, 'portions', portions, 'quantity', quantity)) filter (where quantity is not null)) as variants,
coalesce(json_agg(json_build_object('id', variant.id, 'portions', portions, 'quantity', quantity)) filter (where quantity is not null), '[]') as variants,
let params = [parameters.id];
let poop = 1;
let str = '';
if(parameters.variant !== undefined) {
params.push(parameters.variant);
++poop;
str += ' and variant.id = $' + poop;
}
if(parameters.store !== undefined) {
params.push(parameters.store);
++poop;
str += ' and menu_item.store = $' + poop;
}
console.log(str);
first(product.id) as id,
first(type) as type,
first(display_brand) as brand,
first(producer) as producer,
first(display_name) as name,
first(strain) as strain,
first(strain_family.name) as strain_family,
COALESCE(
json_agg(
json_build_object(
'id', variant.id,
'portions', portions,
'quantity', quantity,
'stores', fuck
)
)
filter (where quantity is not null)
) as variants,
first(concentration_unit) as concentration_unit,
first(measurement_unit) as measurement_unit,
(select json_agg(distinct jsonb_build_object('id', store.id, 'name', store.name)) from store inner join menu_item on menu_item.store = store.id inner join variant on menu_item.variant = variant.id where product = $1) as stores
product.id,
product.type,
display_brand as brand,
producer,
display_name as name,
strain,
strain_family.name as strain_family,
concentration_unit,
measurement_unit,
range_merge(menu_item.cbd) as cbd,
range_merge(menu_item.thc) as thc,
min(price) as price_min,
max(price) as price_max,
(select coalesce(json_agg(i), '[]') from (select id, portions, quantity from variant where product.id = variant.product) as i) as variants,
(select coalesce(json_agg(i), '[]') from (select distinct on(store.id) store.id, store.url, store.name from store inner join menu_item on store.id = menu_item.store inner join variant on variant.id = menu_item.variant inner join product on product.id = variant.product where product.id = $1) as i) as stores
left outer join (
select
first(variant.id) as id,
first(variant.product) as product,
first(variant.portions) as portions,
first(variant.quantity) as quantity,
json_agg(
json_build_object(
'id', menu_item.id,
'store', menu_item.store,
'cbd_min', menu_item.cbd_min,
'cbd_max', menu_item.cbd_max,
'thc_min', menu_item.thc_min,
'thc_max', menu_item.thc_max,
'price', menu_item.price,
'stock', menu_item.stock
)
) as fuck
from
variant
inner join menu_item on variant.id = menu_item.variant
group by
variant.id
) as variant on (product.id = variant.product)
left outer join strain_family on (product.strain_family = strain_family.id)
left outer join strain_family on product.strain_family = strain_family.id
left outer join variant on variant.product = product.id
left outer join menu_item on menu_item.variant = variant.id
case 'product_select'://search for menu_item(s) given variant and / or store and return.
let params = [];
let poop = 0;
let str = '';
if(parameters.variant !== undefined) {
params.push(parameters.variant);
++poop;
str += ' and menu_item.variant = $' + poop;
}
if(parameters.store !== undefined) {
params.push(parameters.store);
++poop;
str += ' and menu_item.store = $' + poop;
}
str = str.slice(5);
ws.send(JSON.stringify({
response_ID: request_ID,
data: (await pool.query(`
select
id,
variant,
store
from
menu_item
where
${str}
`, params)).rows
}));
break;
query += `(default, $${i * 9 + 1}, $${i * 9 + 2}, $${i * 9 + 3}, $${i * 9 + 4}, $${i * 9 + 5}, $${i * 9 + 6}, $${i * 9 + 7}, $${i * 9 + 8}, $${i * 9 + 9}),`;
query += `(default, $${i * 7 + 1}, $${i * 7 + 2}, $${i * 7 + 3}, $${i * 7 + 4}, $${i * 7 + 5}, $${i * 7 + 6}, $${i * 7 + 7}),`;
parameters.menu_items[i].min_cbd,
parameters.menu_items[i].max_cbd,
parameters.menu_items[i].min_thc,
parameters.menu_items[i].max_thc,
`[${parameters.menu_items[i].min_cbd},${parameters.menu_items[i].max_cbd}]`,
`[${parameters.menu_items[i].min_thc},${parameters.menu_items[i].max_thc}]`,
where (menu_item.cbd_min, menu_item.cbd_max, menu_item.thc_min, menu_item.thc_max, menu_item.price, menu_item.featured) is distinct from
(excluded.cbd_min, excluded.cbd_max, excluded.thc_min, excluded.thc_max, excluded.price, excluded.featured)
where (menu_item.cbd, menu_item.thc, menu_item.price, menu_item.featured) is distinct from
(excluded.cbd, excluded.thc, excluded.price, excluded.featured)