CPNWTEF4ZZHBAB565BALMX5QO2CR3Q32YUHE3FMWJO3O25DZNU5AC
ONTV36PSUYFGQS4OJVRW4JO3SA6XMTUN3G4HIO6YVCOLUV5DXXPAC
WZKS2NSIL7VST55EQ7QEF2YG2X3L2Y6W54AIG463ZRH462QR2NWQC
WYTMZJFYVKHR4QH7AV5JUNWXT6NAC5NNQNPZCQSDI6LGI7DVXFYAC
UCY5PVFCT2QIOGR47KFS4KBF2ZPHRBOAIOH6PJEVWCHLMBRBLOMQC
Q3A33UTWKXZATZKX3LQ42MUAWFTWDZDMNVMLKWGC3QF6L6HBLUQAC
VIGS24FLOPPTBLIBZIB2LFMYCDZ3AO4FBXYADAKQMJFNPM4JHAGQC
'image', (select store_image.url from store_image where store_image.store = store.id limit 1)--order by rank someday
'image', (select store_image.url from store_image where store_image.store = store.id limit 1),--order by rank someday
'online', URL is not null and address is null and address2 is null and city is null and postal_code is null and coordinate is null and timezone is null
let wow = await pool.query('select store.url || path as fuck from menu_item inner join store on menu_item.store = store.id where variant = $1 and store = $2', [parameters.variant, parameters.store]);
if(wow.rows.length && wow.rows[0].fuck !== null) {
ws.send(JSON.stringify({
response_ID: request_ID,
data: wow.rows[0].fuck
}));
break;
}
//todo: timeout / decrementing stock(probably a cron job) ) idea: can only add to cart if stock minus sum of all line items menu items from carts that are less than or equal to ready. once beyond ready, actually decrement stock
//or settimeout to delete. if server crashes, on next initialization check all cart age?
//https://medium.com/@betakuang/why-postgresqls-on-conflict-cannot-find-my-partial-unique-index-552327b85e1
let cart = (await pool.query(`insert into cart (user_account, store) values ($1, $2) on conflict (user_account, store) where status is null or status = 'placed' or status = 'ready' do nothing returning id`, [ws.user_ID, parameters.store])).rows;
//unhandled: currently pending order should not be allowed to create new cart.! if we allowed creating new cart while pending order, when an order gets cancelled, status is set to null, and cart will reappear. now there will be 2 carts for same store
//can we solve this with where status is null | placed | ready do nothing ? will it still use the unique partial index? I think so - just update the partial index
let cart = (await pool.query(`insert into cart (user_account, store) values ($1, (select store from menu_item where id = $2)) on conflict (user_account, store) where status is null or status = 'placed' or status = 'ready' do nothing returning id`, [ws.user_ID, parameters.menu_item])).rows;
let kart = (await pool.query(`select id from cart where user_account = $1 and store = $2 and status is null`, [ws.user_ID, parameters.store])).rows;
let kart = (await pool.query(`select id from cart where user_account = $1 and store = (select store from menu_item where id = $2) and status is null`, [ws.user_ID, parameters.menu_item])).rows;