You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any error messages that may be in the console where you ran npm start: no errors
Any error messages in the JS console: none in Chrome.
Describe the bug
I'm using Postgresql. On the update order function I have it so:
export async function updateOrder(id, data, details = []) {
const db = await getDb();
await db.run('BEGIN;');
try {
const updateStatement = sql`
UPDATE CustomerOrder
SET employeeid=$1, customerid=$2, shipcity=$3, shipaddress=$4, shipname=$5, shipvia=$6, shipregion=$7, shipcountry=$8, shippostalcode=$9, requireddate=$10, freight=$11
WHERE id = $12`;
const result = await db.run(updateStatement, data.employeeid, data.customerid, data.shipcity, data.shipaddress, data.shipname, data.shipvia, data.shipregion, data.shipcountry, data.shippostalcode, data.requireddate, data.freight, id);
console.log('result is ', result);
await Promise.all(details.map((detail) => {
return db.run(sql`
UPDATE OrderDetail
SET productid=$1, quantity=$2, unitprice=$3, discount=$4
WHERE id = $5
`, detail.productid, detail.quantity, detail.unitprice, detail.discount, detail.id);
}))
await db.run('COMMIT;');
return { id: result ? result.lastID : undefined };
} catch (e) {
await db.run('ROLLBACK;');
throw e;
}
}
When I'm inside of the edit page, such as /orders/10351/edit, and hit save order, it successfully makes a POST request. And the update is successful. See below:
But afterwards, when it tries to refresh the page with the id that it got back from the POST request, it fails because the db.run command does not return an id. See below.
My tries at solving this problem was to return the res object in mysql-db.ts code snippet below:
return this.measure(q, params, async () => {
let [res, _] = await this.connection.query(q, params);
if (res && typeof (res as any).insertId !== 'undefined') {
let lastID = (res as any).insertId;
return { lastID, res };
}
return { res };
});
But I could not get the object back for some reason.
Another thing I tried was to rebuild the database and table. That did not solve the problem.
I'm really stuck here trying to solve this problem. I would like this to work. Can you help?.. Thank you.
Expected behavior
result variable should return me the id.
The text was updated successfully, but these errors were encountered:
System Information
Describe the bug
I'm using Postgresql. On the update order function I have it so:
When I'm inside of the edit page, such as
/orders/10351/edit
, and hitsave order
, it successfully makes a POST request. And the update is successful. See below:But afterwards, when it tries to refresh the page with the id that it got back from the POST request, it fails because the
db.run
command does not return an id. See below.My tries at solving this problem was to return the
res
object inmysql-db.ts
code snippet below:But I could not get the object back for some reason.
Another thing I tried was to rebuild the database and table. That did not solve the problem.
I'm really stuck here trying to solve this problem. I would like this to work. Can you help?.. Thank you.
result variable should return me the id.
The text was updated successfully, but these errors were encountered: