I’m attempting to insert the question in nodeJs the place the transactionCode
will robotically generate. however in my case after I insert in all of the 5 insert question inserting with the identical transactionCode
as ABC123
however it needs to be inserted with ABC123, ABC124, ABC125, ABC126, AB127
a fair I’m calling this generate perform within the loop then why it not working and producing one after the other and inserts.
please assist how me repair this subject and make my code right.
for (let i = 0; i < 5; i++)
var stmt, transactionCode;
stmt = await con.question("SELECT `token` FROM `table1` ORDER BY `ID` DESC LIMIT 1",
kind: con.QueryTypes.SELECT,
);
// this perform will return auto quantity with +1 to with earlier quantity, suppose my earlier quantity is ABC123 then my subsequent quantity will ABC124
if (stmt.size > 0)
stmt.map(async (merchandise) =>
transactionCode = merchandise.token;
let strings = transactionCode.exchange(/[0-9]/g, "");
let digits = (parseInt(transactionCode.exchange(/[^0-9]/g, "")) + 1).toString();
if (digits.size < 2) digits = ("000" + digits).substr(-3);
transactionCode = strings + digits;
);
else
transactionCode = "ABC123";
let stmt1;
stmt1 = await con.question("INSERT INTO `table2` (`col1`,`col2`) VALUES(:token, :title)",
replacements:
token: transactionCode,
title: req.physique.title
,
kind: con.QueryTypes.INSERT,
transaction: transaction,
);
transaction.commit();
return res.json( code: 200, message: "Generated", standing: "success" );
Hello,
Why not use your debugger to step via the code? For instance the VSCODE editor implements a debugger pretty merely.
Debugging is a vital factor for Node.Js growth.