From eccf7d2dc1c43a264dd1b31fdceef0c8e828719b Mon Sep 17 00:00:00 2001 From: sriramv Date: Wed, 1 Jun 2022 12:03:50 +0530 Subject: [PATCH] updateApi:GWM --- app/controllers/working.notes.controller.js | 34 +++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/controllers/working.notes.controller.js b/app/controllers/working.notes.controller.js index c901d32..4f3d10b 100644 --- a/app/controllers/working.notes.controller.js +++ b/app/controllers/working.notes.controller.js @@ -47,13 +47,35 @@ exports.updateNotes = async (req, res) => { sheet_no = value.index + 1; notesData = await Workingnotes.findOne({where :{losid : req.body.losid , module_name : req.body.module_name, sheet_no : sheet_no , is_active:1}}); - id = notesData.dataValues.id; - notes = JSON.stringify(value); + + if(notesData != undefined) + { + id = notesData.dataValues.id; + notes = JSON.stringify(value); + + // update working notes data + await Workingnotes.update({notes: notes , updatedby: req.body.updatedby} , { where: { id: id } }) + .then(data=>{ logMsg.info("Notes update Success");}) + .catch(err=>{ logMsg.info("Notes update Failed");}); + + }else{ + notes = JSON.stringify(value); + data = { + losid: req.body.losid, + module_name: req.body.module_name, + entity_reference: req.body.entity_reference, + notes: notes, + sheet_no : value.index + 1, + user_id: req.body.user_id, + createdby: req.body.createdby + }; + // insert working notes data + await Workingnotes.create(data) + .then(data=>{ logMsg.info("Notes insert Success");}) + .catch(err=>{ logMsg.info("Notes insert Failed");}); + + } - // update working notes data - await Workingnotes.update({notes: notes , updatedby: req.body.updatedby} , { where: { id: id } }) - .then(data=>{ logMsg.info("Notes update Success");}) - .catch(err=>{ logMsg.info("Notes update Failed");}); }