54TMOAIBD5UBRSWPGW45YZO4VMVKSP7YYKIQ7H4LWSVCN2E3QA4QC
let product = await pool.query('insert into product values (default, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) returning id', [
let product = (await pool.query('insert into product values (default, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) returning id', [
]);
])).rows[0].id;
if(Array.isArray(parameters.variants) && parameters.variants.length) {
let query = 'insert into variant values ';
let params = [];
for(let i = 0; i < parameters.variants.length; ++i) {
if(parameters.variants[i].quantity !== undefined) {
query += `(default, $${i * 3 + 1}, $${i * 3 + 2}, $${i * 3 + 3}),`;
params.push(product);
params.push(parameters.variants[i].portions === undefined ? 0 : Number(parameters.variants[i].portions));
params.push(Number(parameters.variants[i].quantity));//Number(undefined) -> NaN
}
}
//console.log(query);
//console.log(params);
await pool.query(query.slice(0, -1), params);
}