try {
if(Array.isArray(parameters.menu_items) && parameters.menu_items.length) {
let query = 'insert into menu_item values ';
let params = [];
for(let i = 0; i < parameters.menu_items.length; ++i) {
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}),`;
params.push(
parameters.menu_items[i].variant,
parameters.store,
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].price,
parameters.menu_items[i].stock,
Boolean(parameters.menu_items[i].featured)
);
}
await pool.query(query.slice(0, -1), params);
}
ws.send(JSON.stringify({
response_ID: request_ID
}));
} catch(e) {
console.error(e);
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'check log'
}));
}