tango-app-api-trax 3.7.55 → 3.7.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/controllers/internalTrax.controller.js +12 -40
- package/src/controllers/mobileTrax.controller.js +17 -197
- package/src/controllers/traxDashboard.controllers.js +5 -2
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/mobileTrax.routes.js +1 -3
- package/src/controllers/handlebar-helper.js +0 -11
- package/src/hbs/flag.hbs +0 -249
- package/src/hbs/template.hbs +0 -327
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.56",
|
|
4
4
|
"description": "Trax",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,12 +23,11 @@
|
|
|
23
23
|
"firebase-admin": "^13.0.0",
|
|
24
24
|
"fs": "^0.0.1-security",
|
|
25
25
|
"handlebars": "^4.7.8",
|
|
26
|
-
"html-pdf": "^3.0.1",
|
|
27
26
|
"lodash": "^4.17.21",
|
|
28
27
|
"mongodb": "^6.8.0",
|
|
29
28
|
"nodemon": "^3.1.4",
|
|
30
29
|
"path": "^0.12.7",
|
|
31
|
-
"tango-api-schema": "^2.5.
|
|
30
|
+
"tango-api-schema": "^2.5.59",
|
|
32
31
|
"tango-app-api-middleware": "^3.5.2",
|
|
33
32
|
"url": "^0.11.4",
|
|
34
33
|
"winston": "^3.13.1",
|
|
@@ -307,7 +307,7 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
307
307
|
},
|
|
308
308
|
} );
|
|
309
309
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
310
|
-
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering','queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
310
|
+
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
311
311
|
if ( getSections.length ) {
|
|
312
312
|
for ( let element3 of getSections ) {
|
|
313
313
|
let collectQuestions = {};
|
|
@@ -631,11 +631,11 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
631
631
|
// }
|
|
632
632
|
}
|
|
633
633
|
} else {
|
|
634
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring',
|
|
634
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
635
635
|
let storeNameList = allQuestion.map( ( item ) => item.store_id );
|
|
636
|
-
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering','queuealert' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
636
|
+
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
637
637
|
let storeList = storeDetails.map( ( store ) => store.storeId );
|
|
638
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering','queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
638
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
639
639
|
allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
|
|
640
640
|
} else {
|
|
641
641
|
allQuestion = storeDetails.map( ( item ) => {
|
|
@@ -669,7 +669,7 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
669
669
|
client_id: getCLconfig.client_id,
|
|
670
670
|
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
|
|
671
671
|
};
|
|
672
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering'
|
|
672
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
673
673
|
let processData = {
|
|
674
674
|
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
|
|
675
675
|
return { storeName: store.storeName, storeId: store.store_id, events: store.events };
|
|
@@ -910,7 +910,7 @@ async function insertData( requestData ) {
|
|
|
910
910
|
},
|
|
911
911
|
} );
|
|
912
912
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
913
|
-
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring',
|
|
913
|
+
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
914
914
|
if ( getSections.length ) {
|
|
915
915
|
for ( let element3 of getSections ) {
|
|
916
916
|
let collectQuestions = {};
|
|
@@ -1205,11 +1205,11 @@ async function insertData( requestData ) {
|
|
|
1205
1205
|
// }
|
|
1206
1206
|
}
|
|
1207
1207
|
} else {
|
|
1208
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring',
|
|
1208
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
1209
1209
|
let storeNameList = allQuestion.map( ( item ) => item.store_id );
|
|
1210
|
-
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering','queuealert' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
1210
|
+
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
1211
1211
|
let storeList = storeDetails.map( ( store ) => store.storeId );
|
|
1212
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering','queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
1212
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
1213
1213
|
allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
|
|
1214
1214
|
} else {
|
|
1215
1215
|
allQuestion = storeDetails.map( ( item ) => {
|
|
@@ -1243,7 +1243,7 @@ async function insertData( requestData ) {
|
|
|
1243
1243
|
client_id: getCLconfig.client_id,
|
|
1244
1244
|
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
|
|
1245
1245
|
};
|
|
1246
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering','queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
1246
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert' ].includes( getCLconfig.checkListType ) ) {
|
|
1247
1247
|
let processData = {
|
|
1248
1248
|
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
|
|
1249
1249
|
return { storeName: store.storeName, storeId: store.store_id, events: store.events };
|
|
@@ -3203,37 +3203,9 @@ export async function checklistTaskSubmissionDetails( req, res ) {
|
|
|
3203
3203
|
}
|
|
3204
3204
|
let details = [];
|
|
3205
3205
|
if ( req.body.type == 'checklist' ) {
|
|
3206
|
-
details = await processedchecklist.find( { sourceCheckList_id: req.body.checklistId,
|
|
3207
|
-
date_string: 1,
|
|
3208
|
-
checkListName: 1,
|
|
3209
|
-
createdByName: 1,
|
|
3210
|
-
store_id: 1,
|
|
3211
|
-
storeName: 1,
|
|
3212
|
-
submmitedBy: '$userName',
|
|
3213
|
-
submmitedByEmail: '$userEmail',
|
|
3214
|
-
checklistStatus: 1,
|
|
3215
|
-
submitTime: 1,
|
|
3216
|
-
approvalTime: 1,
|
|
3217
|
-
approvalTime_string: 1,
|
|
3218
|
-
approvalByName: 1,
|
|
3219
|
-
approvalByEmail: 1,
|
|
3220
|
-
} );
|
|
3206
|
+
details = await processedchecklist.find( { sourceCheckList_id: req.body.checklistId, date_iso: new Date( dayjs( req.body.date ).format( 'YYYY-MM-DD' ) ) }, { submitTime: '$submitTime_string', status: '$checklistStatus', approvalStatus: '$approvalStatus', approvalTime: '$approvalTime_string', _id: 0 } );
|
|
3221
3207
|
} else {
|
|
3222
|
-
details = await processedTaskService.find( { sourceCheckList_id: req.body.checklistId,
|
|
3223
|
-
date_string: 1,
|
|
3224
|
-
checkListName: 1,
|
|
3225
|
-
createdByName: 1,
|
|
3226
|
-
store_id: 1,
|
|
3227
|
-
storeName: 1,
|
|
3228
|
-
submmitedBy: '$userName',
|
|
3229
|
-
submmitedByEmail: '$userEmail',
|
|
3230
|
-
checklistStatus: 1,
|
|
3231
|
-
submitTime: 1,
|
|
3232
|
-
approvalTime: 1,
|
|
3233
|
-
approvalTime_string: 1,
|
|
3234
|
-
approvalByName: 1,
|
|
3235
|
-
approvalByEmail: 1,
|
|
3236
|
-
} );
|
|
3208
|
+
details = await processedTaskService.find( { sourceCheckList_id: req.body.checklistId, date_iso: new Date( dayjs( req.body.date ).format( 'YYYY-MM-DD' ) ) }, { submitTime: '$submitTime_string', status: '$checklistStatus', approvalStatus: '$approvalStatus', approvalTime: '$approvalTime_string', _id: 0 } );
|
|
3237
3209
|
}
|
|
3238
3210
|
return res.sendSuccess( details );
|
|
3239
3211
|
} catch ( e ) {
|
|
@@ -21,19 +21,12 @@ import * as clientService from '../services/clients.services.js';
|
|
|
21
21
|
import { create } from '../services/authentication.service.js';
|
|
22
22
|
import { readFileSync } from 'fs';
|
|
23
23
|
import { join } from 'path';
|
|
24
|
-
|
|
24
|
+
import handlebars from 'handlebars';
|
|
25
25
|
dayjs.extend( customParseFormat );
|
|
26
26
|
dayjs.extend( timeZone );
|
|
27
27
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
|
|
28
28
|
import * as cameraService from '../services/camera.service.js';
|
|
29
29
|
dayjs.extend( isSameOrBefore );
|
|
30
|
-
import * as pdf from 'html-pdf';
|
|
31
|
-
import handlebars from './handlebar-helper.js';
|
|
32
|
-
import fs from 'fs';
|
|
33
|
-
import { fileURLToPath } from 'url';
|
|
34
|
-
import path from 'path';
|
|
35
|
-
const __filename = fileURLToPath( import.meta.url );
|
|
36
|
-
const __dirname = path.dirname( __filename );
|
|
37
30
|
|
|
38
31
|
export async function storeList( req, res ) {
|
|
39
32
|
try {
|
|
@@ -1089,7 +1082,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1089
1082
|
|
|
1090
1083
|
if ( requestData.submittype == 'submit' ) {
|
|
1091
1084
|
reqAnswers.forEach( ( reqA ) => {
|
|
1092
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage'
|
|
1085
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
1093
1086
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
1094
1087
|
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1095
1088
|
}
|
|
@@ -1227,7 +1220,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1227
1220
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1228
1221
|
};
|
|
1229
1222
|
newArray.push( structure );
|
|
1230
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle'
|
|
1223
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
1231
1224
|
let qaans = qaAnswers[j].answers;
|
|
1232
1225
|
let ms = [];
|
|
1233
1226
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
@@ -1283,7 +1276,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1283
1276
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1284
1277
|
};
|
|
1285
1278
|
newArray.push( structure );
|
|
1286
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple'
|
|
1279
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
1287
1280
|
let qaans = qaAnswers[j].answers;
|
|
1288
1281
|
let mcmo = [];
|
|
1289
1282
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
@@ -1343,7 +1336,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1343
1336
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1344
1337
|
};
|
|
1345
1338
|
newArray.push( structure );
|
|
1346
|
-
} else if (
|
|
1339
|
+
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1347
1340
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1348
1341
|
let mcmi = [];
|
|
1349
1342
|
// for (let k = 0; k < qaans.length; k++) {
|
|
@@ -1373,9 +1366,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1373
1366
|
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1374
1367
|
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1375
1368
|
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1376
|
-
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1377
|
-
newAnswer.answerType = separatedArray[s].answerType;
|
|
1378
|
-
}
|
|
1379
1369
|
mcmi.push( newAnswer );
|
|
1380
1370
|
}
|
|
1381
1371
|
}
|
|
@@ -2012,32 +2002,6 @@ export async function submitChecklist( req, res ) {
|
|
|
2012
2002
|
};
|
|
2013
2003
|
console.log( 'inserttraxlogs =>', inserttraxlogs );
|
|
2014
2004
|
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2015
|
-
let checklistDetails = await checklistService.findOne( { _id: getchecklist[0].sourceCheckList_id }, { notifyFlags: 1, approver: 1 } );
|
|
2016
|
-
if ( checklistDetails?.notifyFlags?.notifyType?.length ) {
|
|
2017
|
-
let emailList = checklistDetails?.notifyFlags?.notifyType.includes( 'approver' ) ? checklistDetails.approver.flatMap( ( ele ) => ele?.value ): [];
|
|
2018
|
-
emailList = [ ...emailList, ...checklistDetails?.notifyFlags?.notifyType?.users.flatMap( ( ele ) => ele?.value ) ];
|
|
2019
|
-
let data = {
|
|
2020
|
-
storeName: getchecklist[0].storeName,
|
|
2021
|
-
flagCount: updateData.questionFlag,
|
|
2022
|
-
checklistName: getchecklist[0].checkListName,
|
|
2023
|
-
submittedBy: getchecklist[0].userName,
|
|
2024
|
-
time: updateData.submitMobileTime,
|
|
2025
|
-
domain: JSON.parse( process.env.URL ).domain,
|
|
2026
|
-
};
|
|
2027
|
-
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialExtentionEmail.hbs', 'utf8' );
|
|
2028
|
-
const template = Handlebars.compile( templateHtml );
|
|
2029
|
-
const html = template( { data: data } );
|
|
2030
|
-
emailList.forEach( ( email ) => {
|
|
2031
|
-
let params = {
|
|
2032
|
-
toEmail: email,
|
|
2033
|
-
mailSubject: 'TangoEye | Checklist Flag',
|
|
2034
|
-
htmlBody: html,
|
|
2035
|
-
attachment: '',
|
|
2036
|
-
sourceEmail: JSON.parse( process.env.SES ).adminEmail,
|
|
2037
|
-
};
|
|
2038
|
-
sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
|
|
2039
|
-
} );
|
|
2040
|
-
}
|
|
2041
2005
|
}
|
|
2042
2006
|
|
|
2043
2007
|
return res.sendSuccess( 'Checklist Updated Successfully' );
|
|
@@ -3266,7 +3230,6 @@ export async function questionList( req, res ) {
|
|
|
3266
3230
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3267
3231
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3268
3232
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3269
|
-
sourceCheckList_id: 1,
|
|
3270
3233
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3271
3234
|
allowedStoreLocation: {
|
|
3272
3235
|
$cond: {
|
|
@@ -3322,7 +3285,7 @@ export async function questionList( req, res ) {
|
|
|
3322
3285
|
}
|
|
3323
3286
|
|
|
3324
3287
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3325
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3288
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3326
3289
|
let checkvalidation = null;
|
|
3327
3290
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3328
3291
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -3376,24 +3339,24 @@ export async function questionList( req, res ) {
|
|
|
3376
3339
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
3377
3340
|
}
|
|
3378
3341
|
|
|
3379
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3342
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3380
3343
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3381
3344
|
if ( ansIndex ) {
|
|
3382
3345
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3383
3346
|
}
|
|
3384
3347
|
}
|
|
3385
|
-
if (
|
|
3348
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3386
3349
|
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
3387
3350
|
// let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3388
3351
|
let manswer = `${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3389
|
-
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': ''
|
|
3352
|
+
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3390
3353
|
} else {
|
|
3391
3354
|
|
|
3392
3355
|
}
|
|
3393
3356
|
}
|
|
3394
3357
|
}
|
|
3395
3358
|
}
|
|
3396
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3359
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3397
3360
|
Multianswer.forEach( ( item ) => {
|
|
3398
3361
|
if ( item.validationAnswer == null ) {
|
|
3399
3362
|
item.answer = null;
|
|
@@ -3405,11 +3368,11 @@ export async function questionList( req, res ) {
|
|
|
3405
3368
|
question.Multianswer = Multianswer;
|
|
3406
3369
|
}
|
|
3407
3370
|
}
|
|
3408
|
-
if (
|
|
3371
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3409
3372
|
if ( Multianswer.length ) {
|
|
3410
3373
|
question.Multianswer = Multianswer;
|
|
3411
3374
|
} else {
|
|
3412
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null
|
|
3375
|
+
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3413
3376
|
question.Multianswer = Multianswer;
|
|
3414
3377
|
}
|
|
3415
3378
|
}
|
|
@@ -3454,11 +3417,6 @@ export async function questionList( req, res ) {
|
|
|
3454
3417
|
}
|
|
3455
3418
|
}
|
|
3456
3419
|
|
|
3457
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
3458
|
-
if ( checklisDetails ) {
|
|
3459
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
3460
|
-
}
|
|
3461
|
-
|
|
3462
3420
|
return res.sendSuccess( getchecklist );
|
|
3463
3421
|
}
|
|
3464
3422
|
} catch ( e ) {
|
|
@@ -4280,7 +4238,6 @@ export async function questionListV1( req, res ) {
|
|
|
4280
4238
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
4281
4239
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
4282
4240
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
4283
|
-
sourceCheckList_id: { $ifNull: [ '$sourceCheckList_id', '' ] },
|
|
4284
4241
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
4285
4242
|
allowedStoreLocation: {
|
|
4286
4243
|
$cond: {
|
|
@@ -4336,7 +4293,7 @@ export async function questionListV1( req, res ) {
|
|
|
4336
4293
|
}
|
|
4337
4294
|
|
|
4338
4295
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
4339
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4296
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4340
4297
|
let checkvalidation = null;
|
|
4341
4298
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
4342
4299
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -4388,13 +4345,13 @@ export async function questionListV1( req, res ) {
|
|
|
4388
4345
|
|
|
4389
4346
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
4390
4347
|
}
|
|
4391
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4348
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4392
4349
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
4393
4350
|
if ( ansIndex ) {
|
|
4394
4351
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
4395
4352
|
}
|
|
4396
4353
|
}
|
|
4397
|
-
if ( question.answerType == 'multipleImage'
|
|
4354
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
4398
4355
|
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
4399
4356
|
let manswer = `${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
4400
4357
|
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
@@ -4404,7 +4361,7 @@ export async function questionListV1( req, res ) {
|
|
|
4404
4361
|
}
|
|
4405
4362
|
}
|
|
4406
4363
|
}
|
|
4407
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4364
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4408
4365
|
Multianswer.forEach( ( item ) => {
|
|
4409
4366
|
if ( item.validationAnswer == null ) {
|
|
4410
4367
|
item.answer = null;
|
|
@@ -4416,7 +4373,7 @@ export async function questionListV1( req, res ) {
|
|
|
4416
4373
|
question.Multianswer = Multianswer;
|
|
4417
4374
|
}
|
|
4418
4375
|
}
|
|
4419
|
-
if ( question.answerType == 'multipleImage'
|
|
4376
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
4420
4377
|
if ( Multianswer.length ) {
|
|
4421
4378
|
question.Multianswer = Multianswer;
|
|
4422
4379
|
} else {
|
|
@@ -4465,11 +4422,6 @@ export async function questionListV1( req, res ) {
|
|
|
4465
4422
|
}
|
|
4466
4423
|
}
|
|
4467
4424
|
|
|
4468
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
4469
|
-
if ( checklisDetails ) {
|
|
4470
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
4471
|
-
}
|
|
4472
|
-
|
|
4473
4425
|
return res.sendSuccess( getchecklist );
|
|
4474
4426
|
}
|
|
4475
4427
|
} catch ( e ) {
|
|
@@ -4532,135 +4484,3 @@ export async function chunkUpload( req, res ) {
|
|
|
4532
4484
|
return res.sendError( e, 500 );
|
|
4533
4485
|
}
|
|
4534
4486
|
}
|
|
4535
|
-
|
|
4536
|
-
export async function downloadChecklist( req, res ) {
|
|
4537
|
-
try {
|
|
4538
|
-
let requestData = req.body;
|
|
4539
|
-
|
|
4540
|
-
if ( !requestData.checklistId ) {
|
|
4541
|
-
res.sendBadRequest( 'checklistId is Required' );
|
|
4542
|
-
}
|
|
4543
|
-
|
|
4544
|
-
let checklistDetails;
|
|
4545
|
-
|
|
4546
|
-
if ( requestData.type == 'checklist' ) {
|
|
4547
|
-
checklistDetails = await processedchecklist.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4548
|
-
} else {
|
|
4549
|
-
checklistDetails = await processedTask.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4550
|
-
}
|
|
4551
|
-
|
|
4552
|
-
if ( !checklistDetails ) {
|
|
4553
|
-
return res.sendError( 'No data found', 204 );
|
|
4554
|
-
}
|
|
4555
|
-
|
|
4556
|
-
let storeDetails = await storeService.findOne( { storeId: checklistDetails.store_id }, { storeProfile: 1 } );
|
|
4557
|
-
if ( !storeDetails ) {
|
|
4558
|
-
return res.sendError( 'No data found', 204 );
|
|
4559
|
-
}
|
|
4560
|
-
|
|
4561
|
-
let clientDetails = await clientService.findOne( { clientId: checklistDetails.client_id } );
|
|
4562
|
-
|
|
4563
|
-
if ( !clientDetails ) {
|
|
4564
|
-
return res.sendError( 'No client found', 204 );
|
|
4565
|
-
}
|
|
4566
|
-
|
|
4567
|
-
checklistDetails = { ...checklistDetails.toObject(), ...storeDetails?.toObject()?.storeProfile };
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
let scheduleDateTime = dayjs( checklistDetails.submitTime );
|
|
4571
|
-
checklistDetails.submitDate = scheduleDateTime.format( 'DD MMM, YYYY' );
|
|
4572
|
-
checklistDetails.submitTime = scheduleDateTime.format( 'hh:mm A' );
|
|
4573
|
-
if ( clientDetails?.profileDetails?.logo ) {
|
|
4574
|
-
let bucketpath = checklistDetails.client_id + '/logo';
|
|
4575
|
-
|
|
4576
|
-
let params = {
|
|
4577
|
-
Bucket: JSON.parse( process.env.BUCKET )?.assets,
|
|
4578
|
-
file_path: `${bucketpath}/${clientDetails?.profileDetails?.logo}`,
|
|
4579
|
-
};
|
|
4580
|
-
let url = await signedUrl( params );
|
|
4581
|
-
let brandImage = await convertUrltoBase64( url );
|
|
4582
|
-
if ( brandImage ) {
|
|
4583
|
-
checklistDetails['brandLogo'] = brandImage;
|
|
4584
|
-
}
|
|
4585
|
-
}
|
|
4586
|
-
checklistDetails['brandName'] = clientDetails?.clientName;
|
|
4587
|
-
for ( let section of checklistDetails.questionAnswers ) {
|
|
4588
|
-
for ( let question of section.questions ) {
|
|
4589
|
-
question.remarks = question.remarks == null || question.remarks == 'null' ? '' : question.remarks;
|
|
4590
|
-
for ( let answer of question.userAnswer ) {
|
|
4591
|
-
if ( answer?.referenceImage?.trim() ) {
|
|
4592
|
-
let inputData = {
|
|
4593
|
-
Bucket: JSON.parse( process.env.BUCKET )?.sop,
|
|
4594
|
-
file_path: answer.referenceImage,
|
|
4595
|
-
};
|
|
4596
|
-
let url = await signedUrl( inputData );
|
|
4597
|
-
const base64Image = await convertUrltoBase64( url );
|
|
4598
|
-
if ( base64Image ) {
|
|
4599
|
-
answer.referenceImage = base64Image;
|
|
4600
|
-
}
|
|
4601
|
-
}
|
|
4602
|
-
if ( answer.validationType == 'Capture Image' && answer?.validationAnswer?.trim() ) {
|
|
4603
|
-
let inputData = {
|
|
4604
|
-
Bucket: JSON.parse( process.env.BUCKET )?.sop,
|
|
4605
|
-
file_path: answer.validationAnswer,
|
|
4606
|
-
};
|
|
4607
|
-
let url = await signedUrl( inputData );
|
|
4608
|
-
const base64Image = await convertUrltoBase64( url );
|
|
4609
|
-
if ( base64Image ) {
|
|
4610
|
-
answer.validationAnswer = base64Image;
|
|
4611
|
-
}
|
|
4612
|
-
}
|
|
4613
|
-
if ( answer?.answer?.trim() && [ 'image', 'descriptiveImage', 'multipleImage', 'image/video' ].includes( question.answerType ) ) {
|
|
4614
|
-
let inputData = {
|
|
4615
|
-
Bucket: JSON.parse( process.env.BUCKET )?.sop,
|
|
4616
|
-
file_path: answer.answer,
|
|
4617
|
-
};
|
|
4618
|
-
let url = await signedUrl( inputData );
|
|
4619
|
-
const base64Image = await convertUrltoBase64( url );
|
|
4620
|
-
if ( base64Image ) {
|
|
4621
|
-
answer.answer = base64Image;
|
|
4622
|
-
}
|
|
4623
|
-
}
|
|
4624
|
-
}
|
|
4625
|
-
}
|
|
4626
|
-
}
|
|
4627
|
-
const targetFolder = path.join( __dirname, '..', '/hbs/template.hbs' );
|
|
4628
|
-
const templateHtml = fs.readFileSync( targetFolder, 'utf8' );
|
|
4629
|
-
const template = handlebars.compile( templateHtml );
|
|
4630
|
-
const html = template( { data: checklistDetails } );
|
|
4631
|
-
pdf.create( html ).toBuffer( ( err, buffer ) => {
|
|
4632
|
-
if ( err ) {
|
|
4633
|
-
res.status( 500 ).send( 'Error Generating PDF' );
|
|
4634
|
-
} else {
|
|
4635
|
-
res.setHeader( 'Content-Disposition', 'attachment; filename=checkListDetails.pdf' );
|
|
4636
|
-
res.contentType( 'application/pdf' );
|
|
4637
|
-
res.send( buffer );
|
|
4638
|
-
}
|
|
4639
|
-
} );
|
|
4640
|
-
} catch ( e ) {
|
|
4641
|
-
console.log( 'getChecklistQuestionAnswers =>', e );
|
|
4642
|
-
return false;
|
|
4643
|
-
}
|
|
4644
|
-
}
|
|
4645
|
-
|
|
4646
|
-
async function convertUrltoBase64( url ) {
|
|
4647
|
-
try {
|
|
4648
|
-
const response = await fetch( url );
|
|
4649
|
-
|
|
4650
|
-
if ( !response.ok ) {
|
|
4651
|
-
throw new Error( 'Failed to fetch image' );
|
|
4652
|
-
}
|
|
4653
|
-
|
|
4654
|
-
const contentType = response.headers.get( 'content-type' );
|
|
4655
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4656
|
-
|
|
4657
|
-
const base64Image =
|
|
4658
|
-
`data:${contentType};base64,` +
|
|
4659
|
-
Buffer.from( arrayBuffer ).toString( 'base64' );
|
|
4660
|
-
|
|
4661
|
-
return base64Image;
|
|
4662
|
-
} catch ( error ) {
|
|
4663
|
-
// console.error( 'Error fetching image:', error.message );
|
|
4664
|
-
return false;
|
|
4665
|
-
}
|
|
4666
|
-
}
|
|
@@ -301,7 +301,8 @@ export const checklistPerformance = async ( req, res ) => {
|
|
|
301
301
|
findQuery.push( { $addFields: { cheklistlowercase: { $toLower: '$checkListName' } } } );
|
|
302
302
|
query = { cheklistlowercase: { $in: checkListSearch } };
|
|
303
303
|
} else {
|
|
304
|
-
|
|
304
|
+
const safeSearch = escapeRegex( req.body?.searchValue );
|
|
305
|
+
query = { checkListName: { $regex: safeSearch, $options: 'i' } };
|
|
305
306
|
}
|
|
306
307
|
findQuery.push( { $match: { $or: [ query ] } } );
|
|
307
308
|
}
|
|
@@ -4253,7 +4254,9 @@ export async function getUserEmails( req, res ) {
|
|
|
4253
4254
|
return res.sendError( e, 500 );
|
|
4254
4255
|
}
|
|
4255
4256
|
}
|
|
4256
|
-
|
|
4257
|
+
function escapeRegex( text ) {
|
|
4258
|
+
return text.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
4259
|
+
}
|
|
4257
4260
|
// async function getChecklistUsers( loginUser ) {
|
|
4258
4261
|
// try {
|
|
4259
4262
|
// // userType, role, clientId, userEmail All Key Required Fields
|