const db = require("../config/dbproc.js"); const Adapter = require("./dbadapter.js"); const QRCode = require("qrcode"); const fs = require("fs"); function getToken() { try { var n1 = Math.floor(Math.random() * 9) + 0; var n2 = Math.floor(Math.random() * 9) + 0; var n3 = Math.floor(Math.random() * 9) + 0; var n4 = Math.floor(Math.random() * 9) + 0; var n5 = Math.floor(Math.random() * 9) + 0; var n6 = Math.floor(Math.random() * 9) + 0; var otp = n1.toString() + n2.toString() + n3.toString() + n4.toString() + n5.toString() + n6.toString(); // console.log(otp); return otp; } catch (error) { return error; } } class ProcJustificationAdapter extends Adapter { constructor() { super(); } async queryPrList(req, callback) { var apires = this.getApiResultDefined(); try { let nik = req.query.nik; let isused = req.query.isused; let swherenik = ""; if (nik) { swherenik = "iby='" + nik + "' and "; } // let qry = "select * from vw_pr where status in(2,6) and isused="+isused+" and iby='"+nik+"' order by id asc"; let qry = "select * from vw_pr where status in(2,6) and " + swherenik + " isused=" + isused + " order by id asc"; // console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { if (result.length > 0) { apires.success = true; apires.data = JSON.parse(JSON.stringify(result)); } else { apires.meta.code = 200; apires.meta.message = "Record Not Found"; } callback(null, apires); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryNewProcJustification(req, callback) { var apires = this.getApiResultDefined(); try { let idxpr = req.body.idxpr; let prnumber = req.body.prnumber; let procjustificationnumber = req.body.procjustificationnumber; let idxjustification = req.body.idxjustification; let justificationnumber = req.body.justificationnumber; let nik = req.body.nik; let ttd = JSON.parse(req.body.ttd); let vendors = JSON.parse(req.body.vendor); let status = -1; let statusdescription = "draft"; let qry = "insert into tbl_procjustification "; qry = qry + "set idxpr='" + idxpr + "',prnumber='" + prnumber + "',procjustificationnumber='" + procjustificationnumber + "',idxjustification='" + idxjustification + "',justificationnumber='" + justificationnumber + "',"; qry = qry + "status='" + status + "',statusdescription='" + statusdescription + "',iby='" + nik + "',idt=now()"; // console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { var res = JSON.parse(JSON.stringify(result)); var idxprocjustification = res.insertId; var created = ttd.dibuatoleh; var verify = ttd.diverifikasioleh; var approval = ttd.disetujuioleh; Object.keys(created).forEach(function (key) { var token = getToken(); var idemployee = created[key]["idemployee"]; var nikcreated = created[key]["nik"]; qry = "insert into tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nikcreated + "',category='CRE',token='" + token + "',imgqr='',iby='" + nik + "',idt=now()"; db.query(qry, [], function (err3, result3, fields3) { return result3; }); }); Object.keys(verify).forEach(function (key) { var token = getToken(); var idemployee = verify[key]["idemployee"]; var nikverify = verify[key]["nik"]; // if(err) return console.log("error occurred") qry = "insert into tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nikverify + "',category='VRF',token='" + token + "',imgqr='',iby='" + nik + "',idt=now()"; db.query(qry, [], function (err3, result3, fields3) { return result3; }); }); Object.keys(approval).forEach(function (key) { var token = getToken(); var idemployee = approval[key]["idemployee"]; var nikapproval = approval[key]["nik"]; // if(err) return console.log("error occurred") qry = "insert into tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nikapproval + "',category='APR',token='" + token + "',imgqr='',iby='" + nik + "',idt=now()"; db.query(qry, [], function (err3, result3, fields3) { return result3; }); }); /* ========================= INSERT VENDORS ========================= */ if (vendors && vendors.length > 0) { vendors.forEach(function (vendor, i) { let numberoffile = i + 1; let qryVendor = "insert into tbl_procjustificationvendor "; qryVendor += "set idxprocjustification='" + idxprocjustification + "',"; qryVendor += "numberoffile='" + numberoffile + "',"; qryVendor += "name='" + vendor.vendorname + "',"; qryVendor += "address='" + vendor.address + "',"; qryVendor += "phone='" + vendor.phone + "',"; qryVendor += vendor.currency_id ? "currency_id='" + vendor.currency_id + "'," : ""; qryVendor += "iby='" + nik + "',idt=now()"; db.query(qryVendor, [], function (errVendor, resultVendor) { if (!errVendor) { let idxvendor = resultVendor.insertId; /* ========================= INSERT VENDOR BOQ ========================= */ if (vendor.boq && vendor.boq.length > 0) { vendor.boq.forEach(function (boq) { let qryBoq = "insert into tbl_procjustificationvendorboq "; qryBoq += "set idxprocjustificationvendor='" + idxvendor + "',"; qryBoq += "items='" + boq.items + "',"; qryBoq += "qty='" + boq.qty + "',"; qryBoq += "unitprice='" + boq.unitprice + "',"; qryBoq += "units='" + boq.units + "',"; qryBoq += "total='" + boq.total + "',"; qryBoq += "iby='" + nik + "',idt=now()"; db.query(qryBoq, [], function (errBoq, resBoq) {}); }); } } }); }); } apires.success = true; apires.meta.message = "Saved Success"; apires.data = res; callback(null, apires); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryUpdateProcJustification(req, filename, callback) { var apires = this.getApiResultDefined(); try { //console.log(filename); let idxprocjustification = req.body.idxprocjustification; let idxpr = req.body.idxpr; let prnumber = req.body.prnumber; let procjustificationnumber = req.body.procjustificationnumber; let idxjustification = req.body.idxjustification; let justificationnumber = req.body.justificationnumber; let filecategory = req.body.filecategory; let descriptionfile = req.body.descriptionfile; let numberoffile = req.body.numberoffile; let ttd = JSON.parse(req.body.ttd); let nik = req.body.nik; let status = req.body.status; let statusdescription = req.body.statusdescription; // let qry = "update tbl_procjustification "; // qry = qry +"set idxpr='"+idxpr+"',prnumber='"+prnumber+"',procjustificationnumber='"+procjustificationnumber+"',idxjustification='"+idxjustification+"',justificationnumber='"+justificationnumber+"',"; // qry = qry +"status='"+status+"',statusdescription='"+statusdescription+"',idxcreated='"+idxcreated+"',nikcreated='"+nikcreated+"',idxverified='"+idxverified+"',nikverified='"+nikverified+"',"; // qry = qry +"idxapproval='"+idxapproval+"',nikapproval='"+nikapproval+"',uby='"+nik+"',udt=now() "; // qry = qry +"where _idx='"+idxprocjustification+"'"; let qry = "update tbl_procjustification "; qry = qry + "set idxpr='" + idxpr + "',prnumber='" + prnumber + "',procjustificationnumber='" + procjustificationnumber + "',idxjustification='" + idxjustification + "',justificationnumber='" + justificationnumber + "',"; qry = qry + "status='" + status + "',statusdescription='" + statusdescription + "',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + idxprocjustification + "'"; // console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { qry = "select _idx from tbl_procjustificationdoc "; qry = qry + "where idxheader='" + idxprocjustification + "' and numberoffile='" + numberoffile + "' and filecategory='" + filecategory + "' and isdeleted=0 order by _idx desc limit 1"; // console.log(qry); db.query(qry, [], function (err2, results2) { if (err2) { apires.meta["message"] = err2.toString(); apires.meta["code"] = 500; callback("err", apires); } else { qry = "insert into tbl_procjustificationdoc "; qry = qry + "set idxheader='" + idxprocjustification + "',numberoffile='" + numberoffile + "',filecategory='" + filecategory + "',"; qry = qry + "filename='" + filename + "',descriptionfile='" + descriptionfile + "',iby='" + nik + "',idt=now()"; if (results2.length >= 1) { qry = "update tbl_procjustificationdoc "; qry = qry + "set idxheader='" + idxprocjustification + "',numberoffile='" + numberoffile + "',filecategory='" + filecategory + "',"; qry = qry + "filename='" + filename + "',descriptionfile='" + descriptionfile + "',uby='" + nik + "',udt=now() "; qry = qry + "where idxheader='" + idxprocjustification + "' and numberoffile='" + numberoffile + "' and filecategory='" + filecategory + "' and isdeleted=0"; } db.query(qry, [], function (err3, results3) { if (err3) { apires.meta["message"] = err3.toString(); apires.meta["code"] = 500; callback("err", apires); } else { // === Update ttd var created = ttd.dibuatoleh; var verify = ttd.diverifikasioleh; var approval = ttd.disetujuioleh; Object.keys(created).forEach(function (key) { var token = getToken(); var id = created[key]["id"]; var idemployee = created[key]["idemployee"]; var nik = created[key]["nik"]; var action = created[key]["action"]; qry = "insert into tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nik + "',category='CRE',token='" + token + "',imgqr='',iby='" + nik + "',idt=now()"; if (action == "update") { qry = "update tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nik + "',category='CRE',token='" + token + "',imgqr='',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + id + "'"; } if (action == "delete") { qry = "update tbl_procjustificationttd set isdeleted=1,dby='" + nik + "',ddt=now() "; qry = qry + "where _idx='" + id + "'"; } db.query(qry, [], function (err3, result3, fields3) { return result3; }); }); Object.keys(verify).forEach(function (key) { var token = getToken(); var id = verify[key]["id"]; var idemployee = verify[key]["idemployee"]; var nik = verify[key]["nik"]; var action = verify[key]["action"]; qry = "insert into tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nik + "',category='VRF',token='" + token + "',imgqr='',iby='" + nik + "',idt=now()"; if (action == "update") { qry = "update tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nik + "',category='VRF',token='" + token + "',imgqr='',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + id + "'"; } if (action == "delete") { qry = "update tbl_procjustificationttd set isdeleted=1,dby='" + nik + "',ddt=now() "; qry = qry + "where _idx='" + id + "'"; } db.query(qry, [], function (err3, result3, fields3) { return result3; }); }); Object.keys(approval).forEach(function (key) { var token = getToken(); var id = approval[key]["id"]; var idemployee = approval[key]["idemployee"]; var nik = approval[key]["nik"]; var action = approval[key]["action"]; qry = "insert into tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nik + "',category='APR',token='" + token + "',imgqr='',iby='" + nik + "',idt=now()"; if (action == "update") { qry = "update tbl_procjustificationttd set idxjustification='" + idxprocjustification + "',idemployee='" + idemployee + "',"; qry = qry + "nik='" + nik + "',category='APR',token='" + token + "',imgqr='',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + id + "'"; } if (action == "delete") { qry = "update tbl_procjustificationttd set isdeleted=1,dby='" + nik + "',ddt=now() "; qry = qry + "where _idx='" + id + "'"; } db.query(qry, [], function (err3, result3, fields3) { return result3; }); }); var res = JSON.parse(JSON.stringify(results3)); apires.success = true; apires.meta.message = "Updated Success"; apires.data = res; callback(null, apires); } }); } }); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryInquiryProcJustification(req, filename, callback) { var apires = this.getApiResultDefined(); try { let idxprocjustification = req.body.idxprocjustification; let filecategory = req.body.filecategory; let numberoffile = req.body.numberoffile; let descriptionfile = req.body.descriptionfile; let nik = req.body.nik; let qry = "select _idx from tbl_procjustificationdoc "; qry = qry + "where idxheader='" + idxprocjustification + "' and numberoffile='" + numberoffile + "' and filecategory='" + filecategory + "' and isdeleted=0 order by _idx desc limit 1"; // console.log(qry); db.query(qry, [], function (err2, results2) { if (err2) { apires.meta["message"] = err2.toString(); apires.meta["code"] = 500; callback("err", apires); } else { qry = "insert into tbl_procjustificationdoc "; qry = qry + "set idxheader='" + idxprocjustification + "',numberoffile='" + numberoffile + "',filecategory='" + filecategory + "',"; qry = qry + "descriptionfile='" + descriptionfile + "',filename='" + filename + "',iby='" + nik + "',idt=now()"; if (results2.length >= 1) { qry = "update tbl_procjustificationdoc "; qry = qry + "set idxheader='" + idxprocjustification + "',numberoffile='" + numberoffile + "',filecategory='" + filecategory + "',"; qry = qry + "descriptionfile='" + descriptionfile + "',filename='" + filename + "',uby='" + nik + "',udt=now() "; qry = qry + "where idxheader='" + idxprocjustification + "' and numberoffile='" + numberoffile + "' and filecategory='" + filecategory + "' and isdeleted=0"; } console.log(qry); db.query(qry, [], function (err3, results3) { if (err3) { apires.meta["message"] = err3.toString(); apires.meta["code"] = 500; callback("err", apires); } else { var res = JSON.parse(JSON.stringify(results3)); apires.success = true; apires.meta.message = "Updated Success"; apires.data = res; callback(null, apires); } }); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async querySignedProcJustification(req, callback) { var apires = this.getApiResultDefined(); try { let idxprocjustification = req.body.idxprocjustification; let nik = req.body.nik; let idxsigned = req.body.idxsigned; let idemployeesigned = req.body.idemployeesigned; let niksigned = req.body.niksigned; let datesigned = req.body.datesigned; let idxsignedvrf = req.body.idxsignedvrf ?? 0; let idemployeevrf = req.body.idemployeevrf ?? 0; let niksignedvrf = req.body.niksignedvrf ?? 0; let idxsignedapr = req.body.idxsignedapr ?? 0; let idemployeeapr = req.body.idemployeeapr ?? 0; let niksignedapr = req.body.niksignedapr ?? 0; let status = req.body.status; let statusdescription = req.body.statusdescription; //"Verified"; var token = this.getToken(); var filepng = token + ".png"; // token =getToken(); token = token + "," + niksigned; // console.log(req.body); let qry = "update tbl_procjustification "; qry = qry + "set status='" + status + "',statusdescription='" + statusdescription + "',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + idxprocjustification + "'"; // console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { if (status == 0) { var qry = "update tbl_procjustificationttd set idemployee='" + idemployeevrf + "',nik='" + niksignedvrf + "',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + idxsignedvrf + "'"; db.query(qry, [], function (err, result, fields) {}); var qry = "update tbl_procjustificationttd set idemployee='" + idemployeeapr + "',nik='" + niksignedapr + "',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + idxsignedapr + "'"; db.query(qry, [], function (err, result, fields) {}); } QRCode.toDataURL(token, function (err, code) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { var imageBuffer = Adapter.decodeBase64Image(code); fs.writeFile("./assets/pngproc/" + filepng, imageBuffer.data, function (err) { // console.log(err); if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback(err.toString(), apires); } else { // var qry = "update tbl_procjustificationttd set token=md5('"+token+"'),imgqr='"+filepng+"',issigned='1',signeddate='"+datesigned+"',uby='"+nik+"',udt=now() "; var qry = "update tbl_procjustificationttd set idemployee='" + idemployeesigned + "',nik='" + niksigned + "',token='" + token + "',imgqr='" + filepng + "',issigned='1',signeddate='" + datesigned + "',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + idxsigned + "'"; // console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { apires.success = true; // === qry = "select status from tbl_procjustification where _idx='" + idxprocjustification + "'"; db.query(qry, [], function (err, result2, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { var status = result2[0]["status"]; var isverified = 0; if (status == 1) { isverified = 1; } apires.data = { "isverified": isverified, "token": token, "urltoken": process.env.BASEURL + "/main/getimageinfo?route=pngproc&name=" + filepng, }; callback(null, apires); } }); } }); } }); } }); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryDeleteProcJustification(req, callback) { var apires = this.getApiResultDefined(); try { let id = req.body.id; let remarkdeleted = req.body.remarkdeleted; let nik = req.body.nik; let qry = "update tbl_procjustification "; qry = qry + "set isdeleted=1,remarkdeleted='" + remarkdeleted + "',dby='" + nik + "',ddt=now()"; qry = qry + " where _idx='" + id + "'"; db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { apires.success = true; apires.meta.message = "Deleted Success"; callback(null, apires); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryProcJustificationDetail(req, callback) { var apires = this.getApiResultDefined(); try { let _idx = req.query.id; let qry = "select * from vw_procjustification where id='" + _idx + "'"; console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { let dataRows = result.length; if (result.length <= 0) { apires.meta.message = "Record not found"; callback("", apires); } else { Object.keys(result).forEach(function (key) { qry = "select * from vw_procjustificationdoc where idxheader='" + _idx + "' order by id asc"; // console.log(qry); db.query(qry, [], function (err, result2, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("error", apires); } else { result[key]["filedoc"] = JSON.parse(JSON.stringify(result2)); qry = "select * from vw_procjustificationttd where idxheader='" + _idx + "' order by id asc"; // console.log(qry); db.query(qry, [], function (err, result3, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("error", apires); } else { if (result3.length > 0) { var dibuatoleh = []; var diverifikasioleh = []; var disetujuioleh = []; Object.keys(result3).forEach(function (key2) { if (result3[key2]["category"] == "CRE") { dibuatoleh.push(JSON.parse(JSON.stringify(result3[key2]))); } else if (result3[key2]["category"] == "VRF") { diverifikasioleh.push(JSON.parse(JSON.stringify(result3[key2]))); } else { disetujuioleh.push(JSON.parse(JSON.stringify(result3[key2]))); } }); result[key]["ttd"] = { "dibuatoleh": dibuatoleh, "diverifikasioleh": diverifikasioleh, "disetujuioleh": disetujuioleh, }; // result[key]['ttd'] = JSON.parse(JSON.stringify(result3)); } /* ========================= SHOW VENDORS ========================= */ qry = "select * from tbl_procjustificationvendor where idxprocjustification='" + _idx + "' and isdeleted=0 order by numberoffile asc"; db.query(qry, [], function (err, vendors, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("error", apires); } else { if (vendors.length > 0) { let vendorRows = vendors.length; vendors.forEach(function (vendor, vkey) { let qryBoq = "select * from tbl_procjustificationvendorboq where idxprocjustificationvendor='" + vendor._idx + "' and isdeleted=0 order by _idx asc"; db.query(qryBoq, [], function (err, boq, fields) { if (!err) { vendors[vkey]["boq"] = JSON.parse(JSON.stringify(boq)); } if (0 === --vendorRows) { result[key]["vendor"] = JSON.parse(JSON.stringify(vendors)); if (0 === --dataRows) { let resultJson = JSON.stringify(result); resultJson = JSON.parse(resultJson); apires.success = true; apires.data = resultJson; callback(null, apires); } } }); }); } else { result[key]["vendor"] = []; if (0 === --dataRows) { let resultJson = JSON.stringify(result); resultJson = JSON.parse(resultJson); apires.success = true; apires.data = resultJson; callback(null, apires); } } } }); // if (0 === --dataRows) { // let resultJson = JSON.stringify(result); // resultJson = JSON.parse(resultJson); // apires.success = true; // apires.data = resultJson; // callback(null, apires); // } } }); } }); }); } } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryProcJustificationList(req, callback) { var apires = this.getApiResultDefined(); try { let limit = req.body.limit; let offset = req.body.offset; let keyword = req.body.keyword; let nik = req.body.nik; let status = req.body.status; let swherenik = ""; if (nik) { swherenik = "iby='" + nik + "' and "; } // let qry = "select * from vw_procjustification "; // qry = qry +"where (trim(prnumber) like '%"+ keyword +"%' or trim(justificationnumber) like '%"+ keyword +"%') "; // qry = qry +"and iby='"+nik+"' and status in("+status+") order by id asc"; let qry = "select * from vw_procjustification "; qry = qry + "where (trim(prnumber) like '%" + keyword + "%' or trim(justificationnumber) like '%" + keyword + "%') "; qry = qry + "and " + swherenik + " status in(" + status + ") order by id asc"; // console.log(qry); db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { if (result.length > 0) { let pagination = result.length / limit; if (!Number.isInteger(pagination)) { pagination = Math.floor(result.length / limit) + 1; } // let pagination = Adapter.getPagination(result.length, limit); apires.success = true; apires.data.push({ "totalpage": pagination, "totalrows": result.length, }); qry = "select * from vw_procjustification "; qry = qry + "where (trim(prnumber) like '%" + keyword + "%' or trim(justificationnumber) like '%" + keyword + "%') "; qry = qry + "and " + swherenik + " status in(" + status + ") order by id asc limit " + offset + ", " + limit; db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { apires.data.push({ "results": JSON.parse(JSON.stringify(result)), }); callback(null, apires); } }); } else { apires.meta.code = 200; apires.meta.message = "Record Not Found"; callback(null, apires); } } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } async queryUpdateStatusProcJustification(req, callback) { try { var apires = this.getApiResultDefined(); var idxjustification = req.body.idxjustification; var status = req.body.status; var statusdescription = req.body.statusdescription; var nik = req.body.nik; var qry = "update tbl_procjustification set status='" + status + "',statusdescription='" + statusdescription + "',uby='" + nik + "',udt=now() "; qry = qry + "where _idx='" + idxjustification + "'"; db.query(qry, [], function (err, result, fields) { if (err) { apires.meta["message"] = err.toString(); apires.meta["code"] = 500; callback("err", apires); } else { // if(result.length>0){ apires.success = true; apires.data = JSON.parse(JSON.stringify(result)); // } // else{ // apires.meta.code = 200; // apires.meta.message = "Record Not Found"; // } callback(null, apires); } }); } catch (err) { apires.meta.code = 500; apires.meta.message = err.toString(); callback("error", apires); } } } module.exports = ProcJustificationAdapter;