Queue transaction
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-05-02 13:52:57 +02:00
parent ea6b1abdd8
commit d156cb1c30
2 changed files with 9 additions and 5 deletions

View File

@ -15,7 +15,6 @@ module.exports = app => {
WHERE at.id = ?`;
const auth = await db.findOne(query, [token]);
console.log(auth);
if (!auth || isTokenExpired(auth.created, auth.ttl))
throw new Error('Invalid authorization token');
@ -32,8 +31,6 @@ module.exports = app => {
locale: auth.lang
};
console.log(response.locals.auth);
next();
} catch (error) {
next(error);

View File

@ -29,10 +29,14 @@ module.exports = async function(request, response, next) {
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
WHERE status = ''`);
let connection;
let invoiceId;
for (const invoiceOut of invoices) {
try {
invoiceId = invoiceOut.id;
connection = await db.getConnection();
connection.query('START TRANSACTION');
const args = Object.assign({
invoiceId: invoiceOut.id,
recipientId: invoiceOut.clientFk,
@ -57,7 +61,7 @@ module.exports = async function(request, response, next) {
fileName: fileName
});
await db.rawSql('UPDATE invoiceOut SET hasPdf = true WHERE id = ?', [invoiceOut.id]);
connection.query('UPDATE invoiceOut SET hasPdf = true WHERE id = ?', [invoiceOut.id]);
const isToBeMailed = invoiceOut.recipient && invoiceOut.salesPersonFk && invoiceOut.isToBeMailed;
@ -93,8 +97,11 @@ module.exports = async function(request, response, next) {
SET status = "printed",
printed = NOW()
WHERE invoiceFk = ?`;
await db.rawSql(sql, [invoiceOut.id]);
connection.query(sql, [invoiceOut.id]);
connection.query('COMMIT');
} catch (error) {
connection.query('ROLLBACK');
connection.release();
sql = `UPDATE invoiceOut_queue
SET status = ?
WHERE invoiceFk = ?`;