tango-app-api-trax 3.7.54 → 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 +10 -161
- 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/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' ].includes( reqA?.answerType )
|
|
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++ ) {
|
|
@@ -3237,7 +3230,6 @@ export async function questionList( req, res ) {
|
|
|
3237
3230
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3238
3231
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3239
3232
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3240
|
-
sourceCheckList_id: 1,
|
|
3241
3233
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3242
3234
|
allowedStoreLocation: {
|
|
3243
3235
|
$cond: {
|
|
@@ -3293,7 +3285,7 @@ export async function questionList( req, res ) {
|
|
|
3293
3285
|
}
|
|
3294
3286
|
|
|
3295
3287
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3296
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3288
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3297
3289
|
let checkvalidation = null;
|
|
3298
3290
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3299
3291
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -3347,7 +3339,7 @@ export async function questionList( req, res ) {
|
|
|
3347
3339
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
3348
3340
|
}
|
|
3349
3341
|
|
|
3350
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3342
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3351
3343
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3352
3344
|
if ( ansIndex ) {
|
|
3353
3345
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
@@ -3364,7 +3356,7 @@ export async function questionList( req, res ) {
|
|
|
3364
3356
|
}
|
|
3365
3357
|
}
|
|
3366
3358
|
}
|
|
3367
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3359
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3368
3360
|
Multianswer.forEach( ( item ) => {
|
|
3369
3361
|
if ( item.validationAnswer == null ) {
|
|
3370
3362
|
item.answer = null;
|
|
@@ -3425,11 +3417,6 @@ export async function questionList( req, res ) {
|
|
|
3425
3417
|
}
|
|
3426
3418
|
}
|
|
3427
3419
|
|
|
3428
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
3429
|
-
if ( checklisDetails ) {
|
|
3430
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
3420
|
return res.sendSuccess( getchecklist );
|
|
3434
3421
|
}
|
|
3435
3422
|
} catch ( e ) {
|
|
@@ -4251,7 +4238,6 @@ export async function questionListV1( req, res ) {
|
|
|
4251
4238
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
4252
4239
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
4253
4240
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
4254
|
-
sourceCheckList_id: { $ifNull: [ '$sourceCheckList_id', '' ] },
|
|
4255
4241
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
4256
4242
|
allowedStoreLocation: {
|
|
4257
4243
|
$cond: {
|
|
@@ -4307,7 +4293,7 @@ export async function questionListV1( req, res ) {
|
|
|
4307
4293
|
}
|
|
4308
4294
|
|
|
4309
4295
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
4310
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4296
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4311
4297
|
let checkvalidation = null;
|
|
4312
4298
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
4313
4299
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -4359,7 +4345,7 @@ export async function questionListV1( req, res ) {
|
|
|
4359
4345
|
|
|
4360
4346
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
4361
4347
|
}
|
|
4362
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4348
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4363
4349
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
4364
4350
|
if ( ansIndex ) {
|
|
4365
4351
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
@@ -4375,7 +4361,7 @@ export async function questionListV1( req, res ) {
|
|
|
4375
4361
|
}
|
|
4376
4362
|
}
|
|
4377
4363
|
}
|
|
4378
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4364
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4379
4365
|
Multianswer.forEach( ( item ) => {
|
|
4380
4366
|
if ( item.validationAnswer == null ) {
|
|
4381
4367
|
item.answer = null;
|
|
@@ -4436,11 +4422,6 @@ export async function questionListV1( req, res ) {
|
|
|
4436
4422
|
}
|
|
4437
4423
|
}
|
|
4438
4424
|
|
|
4439
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
4440
|
-
if ( checklisDetails ) {
|
|
4441
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
4442
|
-
}
|
|
4443
|
-
|
|
4444
4425
|
return res.sendSuccess( getchecklist );
|
|
4445
4426
|
}
|
|
4446
4427
|
} catch ( e ) {
|
|
@@ -4503,135 +4484,3 @@ export async function chunkUpload( req, res ) {
|
|
|
4503
4484
|
return res.sendError( e, 500 );
|
|
4504
4485
|
}
|
|
4505
4486
|
}
|
|
4506
|
-
|
|
4507
|
-
export async function downloadChecklist( req, res ) {
|
|
4508
|
-
try {
|
|
4509
|
-
let requestData = req.body;
|
|
4510
|
-
|
|
4511
|
-
if ( !requestData.checklistId ) {
|
|
4512
|
-
res.sendBadRequest( 'checklistId is Required' );
|
|
4513
|
-
}
|
|
4514
|
-
|
|
4515
|
-
let checklistDetails;
|
|
4516
|
-
|
|
4517
|
-
if ( requestData.type == 'checklist' ) {
|
|
4518
|
-
checklistDetails = await processedchecklist.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4519
|
-
} else {
|
|
4520
|
-
checklistDetails = await processedTask.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4521
|
-
}
|
|
4522
|
-
|
|
4523
|
-
if ( !checklistDetails ) {
|
|
4524
|
-
return res.sendError( 'No data found', 204 );
|
|
4525
|
-
}
|
|
4526
|
-
|
|
4527
|
-
let storeDetails = await storeService.findOne( { storeId: checklistDetails.store_id }, { storeProfile: 1 } );
|
|
4528
|
-
if ( !storeDetails ) {
|
|
4529
|
-
return res.sendError( 'No data found', 204 );
|
|
4530
|
-
}
|
|
4531
|
-
|
|
4532
|
-
let clientDetails = await clientService.findOne( { clientId: checklistDetails.client_id } );
|
|
4533
|
-
|
|
4534
|
-
if ( !clientDetails ) {
|
|
4535
|
-
return res.sendError( 'No client found', 204 );
|
|
4536
|
-
}
|
|
4537
|
-
|
|
4538
|
-
checklistDetails = { ...checklistDetails.toObject(), ...storeDetails?.toObject()?.storeProfile };
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
let scheduleDateTime = dayjs( checklistDetails.submitTime );
|
|
4542
|
-
checklistDetails.submitDate = scheduleDateTime.format( 'DD MMM, YYYY' );
|
|
4543
|
-
checklistDetails.submitTime = scheduleDateTime.format( 'hh:mm A' );
|
|
4544
|
-
if ( clientDetails?.profileDetails?.logo ) {
|
|
4545
|
-
let bucketpath = checklistDetails.client_id + '/logo';
|
|
4546
|
-
|
|
4547
|
-
let params = {
|
|
4548
|
-
Bucket: JSON.parse( process.env.BUCKET )?.assets,
|
|
4549
|
-
file_path: `${bucketpath}/${clientDetails?.profileDetails?.logo}`,
|
|
4550
|
-
};
|
|
4551
|
-
let url = await signedUrl( params );
|
|
4552
|
-
let brandImage = await convertUrltoBase64( url );
|
|
4553
|
-
if ( brandImage ) {
|
|
4554
|
-
checklistDetails['brandLogo'] = brandImage;
|
|
4555
|
-
}
|
|
4556
|
-
}
|
|
4557
|
-
checklistDetails['brandName'] = clientDetails?.clientName;
|
|
4558
|
-
for ( let section of checklistDetails.questionAnswers ) {
|
|
4559
|
-
for ( let question of section.questions ) {
|
|
4560
|
-
question.remarks = question.remarks == null || question.remarks == 'null' ? '' : question.remarks;
|
|
4561
|
-
for ( let answer of question.userAnswer ) {
|
|
4562
|
-
if ( answer?.referenceImage?.trim() ) {
|
|
4563
|
-
let inputData = {
|
|
4564
|
-
Bucket: JSON.parse( process.env.BUCKET )?.sop,
|
|
4565
|
-
file_path: answer.referenceImage,
|
|
4566
|
-
};
|
|
4567
|
-
let url = await signedUrl( inputData );
|
|
4568
|
-
const base64Image = await convertUrltoBase64( url );
|
|
4569
|
-
if ( base64Image ) {
|
|
4570
|
-
answer.referenceImage = base64Image;
|
|
4571
|
-
}
|
|
4572
|
-
}
|
|
4573
|
-
if ( answer.validationType == 'Capture Image' && answer?.validationAnswer?.trim() ) {
|
|
4574
|
-
let inputData = {
|
|
4575
|
-
Bucket: JSON.parse( process.env.BUCKET )?.sop,
|
|
4576
|
-
file_path: answer.validationAnswer,
|
|
4577
|
-
};
|
|
4578
|
-
let url = await signedUrl( inputData );
|
|
4579
|
-
const base64Image = await convertUrltoBase64( url );
|
|
4580
|
-
if ( base64Image ) {
|
|
4581
|
-
answer.validationAnswer = base64Image;
|
|
4582
|
-
}
|
|
4583
|
-
}
|
|
4584
|
-
if ( answer?.answer?.trim() && [ 'image', 'descriptiveImage', 'multipleImage', 'image/video' ].includes( question.answerType ) ) {
|
|
4585
|
-
let inputData = {
|
|
4586
|
-
Bucket: JSON.parse( process.env.BUCKET )?.sop,
|
|
4587
|
-
file_path: answer.answer,
|
|
4588
|
-
};
|
|
4589
|
-
let url = await signedUrl( inputData );
|
|
4590
|
-
const base64Image = await convertUrltoBase64( url );
|
|
4591
|
-
if ( base64Image ) {
|
|
4592
|
-
answer.answer = base64Image;
|
|
4593
|
-
}
|
|
4594
|
-
}
|
|
4595
|
-
}
|
|
4596
|
-
}
|
|
4597
|
-
}
|
|
4598
|
-
const targetFolder = path.join( __dirname, '..', '/hbs/template.hbs' );
|
|
4599
|
-
const templateHtml = fs.readFileSync( targetFolder, 'utf8' );
|
|
4600
|
-
const template = handlebars.compile( templateHtml );
|
|
4601
|
-
const html = template( { data: checklistDetails } );
|
|
4602
|
-
pdf.create( html ).toBuffer( ( err, buffer ) => {
|
|
4603
|
-
if ( err ) {
|
|
4604
|
-
res.status( 500 ).send( 'Error Generating PDF' );
|
|
4605
|
-
} else {
|
|
4606
|
-
res.setHeader( 'Content-Disposition', 'attachment; filename=checkListDetails.pdf' );
|
|
4607
|
-
res.contentType( 'application/pdf' );
|
|
4608
|
-
res.send( buffer );
|
|
4609
|
-
}
|
|
4610
|
-
} );
|
|
4611
|
-
} catch ( e ) {
|
|
4612
|
-
console.log( 'getChecklistQuestionAnswers =>', e );
|
|
4613
|
-
return false;
|
|
4614
|
-
}
|
|
4615
|
-
}
|
|
4616
|
-
|
|
4617
|
-
async function convertUrltoBase64( url ) {
|
|
4618
|
-
try {
|
|
4619
|
-
const response = await fetch( url );
|
|
4620
|
-
|
|
4621
|
-
if ( !response.ok ) {
|
|
4622
|
-
throw new Error( 'Failed to fetch image' );
|
|
4623
|
-
}
|
|
4624
|
-
|
|
4625
|
-
const contentType = response.headers.get( 'content-type' );
|
|
4626
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4627
|
-
|
|
4628
|
-
const base64Image =
|
|
4629
|
-
`data:${contentType};base64,` +
|
|
4630
|
-
Buffer.from( arrayBuffer ).toString( 'base64' );
|
|
4631
|
-
|
|
4632
|
-
return base64Image;
|
|
4633
|
-
} catch ( error ) {
|
|
4634
|
-
// console.error( 'Error fetching image:', error.message );
|
|
4635
|
-
return false;
|
|
4636
|
-
}
|
|
4637
|
-
}
|
|
@@ -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
|