0

When ever I am trying to use asynchronous transaction in by node js app it is giving me an error during post request that user does not exist. But the same user credentials is working fine if I do a simple get or post from the same server and db.

router.post('/medicineretailsalereturn', async (req, res) => {
    console.log("Medicine Retail Return Calls......");
    console.log(req.body);
    var sequelize = common.setPharmaDBConn4SQL(req.headers['pharma_id']);
    const t = await sequelize.transaction();
    try {
        req.body.bill.med_sale_date = new Date();
        req.body.bill.med_bill_number = billgenerator(3);
        req.body.bill.record_created_date = new Date();
        var medicineSellBill = await MedicineRetailSaleBill.create(req.body.bill, { transaction: t });
        for (var medCount = 0; medCount < req.body.items.length; medCount++) {
            var sellReturnJSON = req.body.items[medCount];
            sellReturnJSON.med_bill_id = medicineSellBill.med_sale_bill_id;
            sellReturnJSON.record_created_date = new Date();
            if(sellReturnJSON.med_bill_number != null) sellReturnJSON.med_sell_bill_number = sellReturnJSON.med_bill_number;
            
            if(sellReturnJSON.med_bill_number == null) {
                sellReturnJSON.med_bill_number = medicineSellBill.med_bill_number;
                console.log("Sell Deatils");
                console.log(sellReturnJSON);
                await MedicineRetailSaleDetails.create(sellReturnJSON, { transaction: t });
            } else {
                sellReturnJSON.med_bill_number = medicineSellBill.med_bill_number;
                console.log("Sell Retun Deatils");
                console.log(sellReturnJSON);
                await MedicineRetailReturnDetails.create(sellReturnJSON, { transaction: t });
            }
        }
        await t.commit();
        res.status(200).send("Medicine Reatils Sell/Return Bill Number :" + medicineSellBill.med_bill_number);
    } catch (error) {
        console.log("Error :" + error)
        await t.rollback();
        res.status(200).send("Medicine Reatils Sell/Return Failed" + error);
    }
});

I can share the entire code if needed. Any help will be highly appriciated.

Krish
  • 11
  • 2
  • Did you check the mysql user write permission on the specified table? – A. Yasar G. Sep 04 '22 at 19:26
  • yes the user is having all privileges in this database .. I am using milesweb remote mysql db – Krish Sep 05 '22 at 07:36
  • I guess this user is really dropped after creating the table which is touched inside the transaction. If you know what I mean could you have a check for such a case? you can use select * from mysql.users to see the user list – A. Yasar G. Sep 05 '22 at 08:34
  • The user is not dropped as I am able to do a get as well as post request using it. Only problem happening while I try to use the above post request. – Krish Sep 05 '22 at 10:53
  • ldgybxav_ph1_admin@49.37.47.142 user and ldgybxav_ph1_admin@127.0.0.1 are different for mysql i guess – A. Yasar G. Sep 05 '22 at 11:55
  • ldgybxav_ph1_admin is the user ... I am connecting to remote db in MilesWeb that is why the ip is 49.37.47.142 and not 127.0.0.1 .. – Krish Sep 06 '22 at 14:27
  • https://stackoverflow.com/questions/10169960/mysql-error-1449-the-user-specified-as-a-definer-does-not-exist – A. Yasar G. Sep 07 '22 at 09:00

0 Answers0