tango-app-api-trax 3.6.0-sec-11 → 3.6.0-task-2
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 -2
- package/src/controllers/download.controller.js +54 -54
- package/src/controllers/gallery.controller.js +22 -0
- package/src/controllers/internalTrax.controller.js +0 -52
- package/src/controllers/mobileTrax.controller.js +203 -92
- package/src/controllers/trax.controller.js +3 -10
- package/src/controllers/traxDashboard.controllers.js +0 -3
- package/src/routes/gallery.routes.js +3 -2
- package/src/routes/internalTraxApi.router.js +1 -2
- package/src/services/checklistQuestion.service.js +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.6.0-
|
|
3
|
+
"version": "3.6.0-task-2",
|
|
4
4
|
"description": "Trax",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"mongodb": "^6.8.0",
|
|
27
27
|
"nodemon": "^3.1.4",
|
|
28
28
|
"path": "^0.12.7",
|
|
29
|
-
"tango-api-schema": "^2.2.
|
|
29
|
+
"tango-api-schema": "^2.2.144",
|
|
30
30
|
"tango-app-api-middleware": "^3.1.77",
|
|
31
31
|
"url": "^0.11.4",
|
|
32
32
|
"winston": "^3.13.1",
|
|
@@ -18,6 +18,11 @@ import mongoose from 'mongoose';
|
|
|
18
18
|
export const downloadInsert = async ( req, res ) => {
|
|
19
19
|
try {
|
|
20
20
|
let requestData = req.body;
|
|
21
|
+
let fromDate = new Date( requestData.fromDate );
|
|
22
|
+
let toDate = new Date( requestData.toDate );
|
|
23
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
24
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
25
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
21
26
|
let name;
|
|
22
27
|
let fileType = requestData?.fileType || 'pdfzip';
|
|
23
28
|
|
|
@@ -39,60 +44,55 @@ export const downloadInsert = async ( req, res ) => {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
// console.log( requestData );
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// // console.log( 'getChecklistCountgetChecklistCount[0].totalCount =>', getChecklistCount[0]?.totalCount );
|
|
92
|
-
// } else {
|
|
93
|
-
// return res.sendError( { error: 'No Data Found' }, 400 );
|
|
94
|
-
// }
|
|
95
|
-
// }
|
|
47
|
+
|
|
48
|
+
if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id != '' ) {
|
|
49
|
+
let getChecklistQuery = [];
|
|
50
|
+
getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, userEmail: 1, checklistStatus: 1, redoStatus: 1 } } );
|
|
51
|
+
|
|
52
|
+
if ( requestData.filtertype ==='Clusters' ) {
|
|
53
|
+
getChecklistQuery.push( {
|
|
54
|
+
$match: {
|
|
55
|
+
$and: [
|
|
56
|
+
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
57
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
58
|
+
{ store_id: { $in: requestData.storeIds } },
|
|
59
|
+
],
|
|
60
|
+
$or: [
|
|
61
|
+
{ checklistStatus: 'submit' },
|
|
62
|
+
{ redoStatus: true },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
} );
|
|
66
|
+
} else {
|
|
67
|
+
// console.log( requestData );
|
|
68
|
+
getChecklistQuery.push( {
|
|
69
|
+
$match: {
|
|
70
|
+
$and: [
|
|
71
|
+
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
72
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
73
|
+
{ userEmail: { $in: requestData.userEmailList } },
|
|
74
|
+
],
|
|
75
|
+
$or: [
|
|
76
|
+
{ checklistStatus: 'submit' },
|
|
77
|
+
{ redoStatus: true },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
} );
|
|
81
|
+
}
|
|
82
|
+
getChecklistQuery.push( { $count: 'totalCount' } );
|
|
83
|
+
|
|
84
|
+
let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
|
|
85
|
+
// console.log( getChecklistCount );
|
|
86
|
+
if ( requestData.insertType === 'task' ) {
|
|
87
|
+
getChecklistCount = await processedTaskService.aggregate( getChecklistQuery );
|
|
88
|
+
}
|
|
89
|
+
if ( getChecklistCount && getChecklistCount[0]?.totalCount && getChecklistCount[0].totalCount > 0 ) {
|
|
90
|
+
// console.log( 'if' );
|
|
91
|
+
// console.log( 'getChecklistCountgetChecklistCount[0].totalCount =>', getChecklistCount[0]?.totalCount );
|
|
92
|
+
} else {
|
|
93
|
+
return res.sendError( { error: 'No Data Found' }, 400 );
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
96
|
|
|
97
97
|
if ( requestData.fileType == 'pdf' ) {
|
|
98
98
|
if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
|
|
@@ -1148,3 +1148,25 @@ export async function checkNotificationCount( req, res ) {
|
|
|
1148
1148
|
return res.sendError( { error: error }, 500 );
|
|
1149
1149
|
}
|
|
1150
1150
|
}
|
|
1151
|
+
|
|
1152
|
+
export async function vehicleCheckInUpdate( req, res ) {
|
|
1153
|
+
try {
|
|
1154
|
+
let requestData = req.body;
|
|
1155
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
1156
|
+
let updateData = { _id: requestData._id };
|
|
1157
|
+
let resultData = await LamdaServiceCall( url.vehicleCheckInUpdate, updateData );
|
|
1158
|
+
if ( resultData ) {
|
|
1159
|
+
if ( resultData.status_code == '200' ) {
|
|
1160
|
+
resultData.message = '';
|
|
1161
|
+
return res.sendSuccess( resultData );
|
|
1162
|
+
} else {
|
|
1163
|
+
return res.sendError( 'No Content', 204 );
|
|
1164
|
+
}
|
|
1165
|
+
} else {
|
|
1166
|
+
return res.sendError( 'No Content', 204 );
|
|
1167
|
+
}
|
|
1168
|
+
} catch ( error ) {
|
|
1169
|
+
logger.error( { error: error, function: 'vehicleCheckInUpdate' } );
|
|
1170
|
+
return res.sendError( { error: error }, 500 );
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
@@ -295,11 +295,6 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
295
295
|
isdeleted: false,
|
|
296
296
|
},
|
|
297
297
|
} );
|
|
298
|
-
sectionQuery.push( {
|
|
299
|
-
$sort: {
|
|
300
|
-
sectionNumber: 1,
|
|
301
|
-
},
|
|
302
|
-
} );
|
|
303
298
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
304
299
|
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
|
|
305
300
|
if ( getSections.length ) {
|
|
@@ -307,9 +302,7 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
307
302
|
let collectQuestions = {};
|
|
308
303
|
collectQuestions.section_id = element3._id;
|
|
309
304
|
collectQuestions.sectionName = element3.section;
|
|
310
|
-
collectQuestions.sectionOldName = element3.sectionOldName || '';
|
|
311
305
|
collectQuestions.questions = element3.question;
|
|
312
|
-
collectQuestions.sectionNumber = element3.sectionNumber|| '';
|
|
313
306
|
collectSections.push( collectQuestions );
|
|
314
307
|
}
|
|
315
308
|
}
|
|
@@ -870,11 +863,6 @@ async function insertData( requestData ) {
|
|
|
870
863
|
isdeleted: false,
|
|
871
864
|
},
|
|
872
865
|
} );
|
|
873
|
-
sectionQuery.push( {
|
|
874
|
-
$sort: {
|
|
875
|
-
sectionNumber: 1,
|
|
876
|
-
},
|
|
877
|
-
} );
|
|
878
866
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
879
867
|
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
|
|
880
868
|
if ( getSections.length ) {
|
|
@@ -2474,43 +2462,3 @@ export async function storecheckExists( data ) {
|
|
|
2474
2462
|
logger.error( { error: error, function: 'internalAISendPushNotification' } );
|
|
2475
2463
|
}
|
|
2476
2464
|
}
|
|
2477
|
-
|
|
2478
|
-
export async function insertAINotification( req, res ) {
|
|
2479
|
-
try {
|
|
2480
|
-
let requestData = req.body;
|
|
2481
|
-
let insertData= [];
|
|
2482
|
-
let findAllUser = await userService.find( { clientId: requestData.clientId, isActive: true } );
|
|
2483
|
-
for ( let user of findAllUser ) {
|
|
2484
|
-
let data= {};
|
|
2485
|
-
data.userId = user._id;
|
|
2486
|
-
data.storeId = requestData.storeId;
|
|
2487
|
-
data.storeName = requestData.storeName;
|
|
2488
|
-
data.captureTime = requestData.captureTime;
|
|
2489
|
-
data.clientId = requestData.clientId;
|
|
2490
|
-
data.sourceCheckList_id = requestData.sourceCheckList_id;
|
|
2491
|
-
data.checkListName = requestData.checkListName;
|
|
2492
|
-
data.notificationType = requestData.notificationType;
|
|
2493
|
-
let payload = {
|
|
2494
|
-
userType: user.userType,
|
|
2495
|
-
role: user.role,
|
|
2496
|
-
assignedStores: user.assignedStores,
|
|
2497
|
-
clientId: user.clientId,
|
|
2498
|
-
email: user.email,
|
|
2499
|
-
};
|
|
2500
|
-
let result = await storecheckExists( payload );
|
|
2501
|
-
if ( result ) {
|
|
2502
|
-
insertData.push( data );
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
// console.log( 'insertData =>', insertData );
|
|
2506
|
-
let create = await notificationModel.insertManynotificationModel( insertData );
|
|
2507
|
-
// console.log( 'create =>', create );
|
|
2508
|
-
if ( create ) {
|
|
2509
|
-
return res.sendSuccess( 'updated successfully' );
|
|
2510
|
-
}
|
|
2511
|
-
} catch ( e ) {
|
|
2512
|
-
logger.error( { error: e, function: 'insertAINotification' } );
|
|
2513
|
-
if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
|
|
2514
|
-
else res.sendError( e, 500 );
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
@@ -64,7 +64,11 @@ export async function storeListv1( req, res ) {
|
|
|
64
64
|
}
|
|
65
65
|
let userChecklist = await processedchecklist.find( { userId: req.user._id, userEmail: req.user.email, date_string: dayjs( req.query.date ).format( 'YYYY-MM-DD' ) }, { store_id: 1, storeName: 1 } );
|
|
66
66
|
|
|
67
|
-
let
|
|
67
|
+
let fromDate = new Date( req.query.date );
|
|
68
|
+
let toDate = new Date( req.query.date );
|
|
69
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
70
|
+
let taskFindQuery = { userId: req.user._id, userEmail: req.user.email, scheduleStartTime_iso: { $lt: toDate }, scheduleEndTime_iso: { $gte: fromDate } };
|
|
71
|
+
let userTask = await processedTask.find( taskFindQuery, { store_id: 1, storeName: 1 } );
|
|
68
72
|
|
|
69
73
|
if ( !userChecklist.length && !userTask.length ) {
|
|
70
74
|
return res.sendSuccess( [] );
|
|
@@ -151,19 +155,15 @@ export async function startChecklist( req, res ) {
|
|
|
151
155
|
|
|
152
156
|
let updateData = {};
|
|
153
157
|
let currentDateTime;
|
|
154
|
-
if ( getBeforeChecklist[0]
|
|
155
|
-
let storeTimeZone = await storeService.findOne( {
|
|
158
|
+
if ( getBeforeChecklist[0].storeName && getBeforeChecklist[0].storeName!='' ) {
|
|
159
|
+
let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
|
|
156
160
|
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
157
161
|
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
158
162
|
} else {
|
|
159
163
|
currentDateTime = dayjs();
|
|
160
164
|
}
|
|
161
165
|
} else {
|
|
162
|
-
|
|
163
|
-
currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
|
|
164
|
-
} else {
|
|
165
|
-
currentDateTime = dayjs();
|
|
166
|
-
}
|
|
166
|
+
currentDateTime = dayjs();
|
|
167
167
|
}
|
|
168
168
|
updateData.checklistStatus = 'inprogress';
|
|
169
169
|
updateData.startMobileTime = requestData?.currentTime;
|
|
@@ -347,40 +347,40 @@ export async function startTask( req, res ) {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
350
|
+
const storeTimeZone = await storeService.findOne(
|
|
351
|
+
{ storeName: task.storeName },
|
|
352
|
+
{ 'storeProfile.timeZone': 1 },
|
|
353
|
+
);
|
|
354
|
+
const currentDateTime = storeTimeZone?.storeProfile?.timeZone ?
|
|
355
|
+
dayjs().tz( storeTimeZone.storeProfile.timeZone ) :
|
|
356
|
+
dayjs();
|
|
357
357
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
358
|
+
|
|
359
|
+
let updatedNewData;
|
|
360
|
+
if ( task.checkListFrom && task.checkListFrom == 'api' ) {
|
|
361
|
+
console.log( 'api if=>' );
|
|
362
|
+
updatedNewData = {
|
|
363
|
+
checklistStatus: 'inprogress',
|
|
364
|
+
startMobileTime: requestData?.currentTime,
|
|
365
|
+
startTime_string: currentDateTime.format( 'hh:mm A, DD MMM YYYY' ),
|
|
366
|
+
startTime: dayjs
|
|
367
|
+
.utc( currentDateTime.format( 'hh:mm A, DD MMM YYYY' ), 'hh:mm A, DD MMM YYYY' )
|
|
368
|
+
.format(),
|
|
369
|
+
};
|
|
366
370
|
} else {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
371
|
+
console.log( 'api else=>' );
|
|
372
|
+
updatedNewData = {
|
|
373
|
+
checklistStatus: 'inprogress',
|
|
374
|
+
startMobileTime: requestData?.currentTime,
|
|
375
|
+
questionAnswers: task.redoStatus ? task.questionAnswers : processedTaskConfig.questionAnswers,
|
|
376
|
+
startTime_string: currentDateTime.format( 'hh:mm A, DD MMM YYYY' ),
|
|
377
|
+
startTime: dayjs
|
|
378
|
+
.utc( currentDateTime.format( 'hh:mm A, DD MMM YYYY' ), 'hh:mm A, DD MMM YYYY' )
|
|
379
|
+
.format(),
|
|
380
|
+
};
|
|
372
381
|
}
|
|
373
382
|
|
|
374
|
-
const updateData =
|
|
375
|
-
checklistStatus: 'inprogress',
|
|
376
|
-
startMobileTime: requestData?.currentTime,
|
|
377
|
-
questionAnswers: task.redoStatus ? task.questionAnswers : processedTaskConfig.questionAnswers,
|
|
378
|
-
startTime_string: currentDateTime.format( 'hh:mm A, DD MMM YYYY' ),
|
|
379
|
-
startTime: dayjs
|
|
380
|
-
.utc( currentDateTime.format( 'hh:mm A, DD MMM YYYY' ), 'hh:mm A, DD MMM YYYY' )
|
|
381
|
-
.format(),
|
|
382
|
-
};
|
|
383
|
-
|
|
383
|
+
const updateData = updatedNewData;
|
|
384
384
|
const updateQuery = {
|
|
385
385
|
_id: new ObjectId( requestData.processedcheckListId ),
|
|
386
386
|
userId: user._id,
|
|
@@ -429,39 +429,40 @@ export async function startTask( req, res ) {
|
|
|
429
429
|
const getUpdatedTask = await processedTask.aggregate( findQuery );
|
|
430
430
|
|
|
431
431
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
question.questionReferenceImage
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
432
|
+
if ( !( task.checkListFrom && task.checkListFrom == 'api' ) ) {
|
|
433
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
434
|
+
await Promise.all(
|
|
435
|
+
getUpdatedTask[0].questionAnswers.map( ( section ) =>
|
|
436
|
+
section.questions.map( async ( question ) => {
|
|
437
|
+
if ( question.questionReferenceImage.length > 0 ) {
|
|
438
|
+
question.questionReferenceImage = await Promise.all(
|
|
439
|
+
question.questionReferenceImage.map( async ( image ) => {
|
|
440
|
+
return await signedUrl( {
|
|
441
|
+
Bucket: bucket.sop,
|
|
442
|
+
file_path: decodeURIComponent( image ),
|
|
443
|
+
} );
|
|
444
|
+
} ),
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
await Promise.all(
|
|
449
|
+
question.answers.map( async ( answer ) => {
|
|
450
|
+
if ( answer.referenceImage.length > 0 ) {
|
|
451
|
+
answer.referenceImage = await Promise.all(
|
|
452
|
+
answer.referenceImage.map( async ( image ) => {
|
|
453
|
+
return await signedUrl( {
|
|
454
|
+
Bucket: bucket.sop,
|
|
455
|
+
file_path: decodeURIComponent( image ),
|
|
456
|
+
} );
|
|
457
|
+
} ),
|
|
458
|
+
);
|
|
459
|
+
}
|
|
443
460
|
} ),
|
|
444
461
|
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
if ( answer.referenceImage.length > 0 ) {
|
|
450
|
-
answer.referenceImage = await Promise.all(
|
|
451
|
-
answer.referenceImage.map( async ( image ) => {
|
|
452
|
-
return await signedUrl( {
|
|
453
|
-
Bucket: bucket.sop,
|
|
454
|
-
file_path: decodeURIComponent( image ),
|
|
455
|
-
} );
|
|
456
|
-
} ),
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
} ),
|
|
460
|
-
);
|
|
461
|
-
} ),
|
|
462
|
-
).flat(),
|
|
463
|
-
);
|
|
464
|
-
|
|
462
|
+
} ),
|
|
463
|
+
).flat(),
|
|
464
|
+
);
|
|
465
|
+
}
|
|
465
466
|
|
|
466
467
|
const logData = {
|
|
467
468
|
store_id: task.store_id,
|
|
@@ -1803,8 +1804,8 @@ export async function submitChecklist( req, res ) {
|
|
|
1803
1804
|
|
|
1804
1805
|
let currentDateTime;
|
|
1805
1806
|
let storeTimeZone;
|
|
1806
|
-
if ( getchecklist[0]
|
|
1807
|
-
storeTimeZone = await storeService.findOne( {
|
|
1807
|
+
if ( getchecklist[0].storeName && getchecklist[0].storeName !='' ) {
|
|
1808
|
+
storeTimeZone = await storeService.findOne( { storeName: { $regex: getchecklist[0].storeName, $options: 'i' }, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
|
|
1808
1809
|
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
1809
1810
|
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
1810
1811
|
} else {
|
|
@@ -2023,30 +2024,33 @@ export async function submitTask( req, res ) {
|
|
|
2023
2024
|
|
|
2024
2025
|
if ( updateResult.modifiedCount > 0 ) {
|
|
2025
2026
|
if ( submittype === 'submit' ) {
|
|
2026
|
-
const
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2027
|
+
const excludedChecklists = [ 'Store Hygiene Check', 'EyeTest QR Verification' ];
|
|
2028
|
+
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2029
|
+
const query1 = [
|
|
2030
|
+
{
|
|
2031
|
+
$match: {
|
|
2032
|
+
userId: user._id,
|
|
2033
|
+
sourceCheckList_id: checklist.sourceCheckList_id,
|
|
2034
|
+
checklistStatus: { $in: [ 'open', 'inprogress' ] },
|
|
2035
|
+
},
|
|
2032
2036
|
},
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2037
|
+
{
|
|
2038
|
+
$project: {
|
|
2039
|
+
_id: 1,
|
|
2040
|
+
date_iso: 1,
|
|
2041
|
+
date_string: 1,
|
|
2042
|
+
},
|
|
2039
2043
|
},
|
|
2040
|
-
|
|
2041
|
-
];
|
|
2044
|
+
];
|
|
2042
2045
|
|
|
2043
|
-
|
|
2046
|
+
const processedTasksToDelete = await processedTask.aggregate( query1 );
|
|
2044
2047
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2048
|
+
if ( processedTasksToDelete?.length ) {
|
|
2049
|
+
const deleteIds = processedTasksToDelete?.filter( ( val ) => val?.date_string !== date )?.map( ( val ) => val?._id );
|
|
2047
2050
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2051
|
+
if ( deleteIds?.length ) {
|
|
2052
|
+
await processedTask.deleteMany( { _id: { $in: deleteIds } } );
|
|
2053
|
+
}
|
|
2050
2054
|
}
|
|
2051
2055
|
}
|
|
2052
2056
|
} else if ( submittype === 'draft' ) {
|
|
@@ -2555,6 +2559,42 @@ export async function dashboardv1( req, res ) {
|
|
|
2555
2559
|
},
|
|
2556
2560
|
];
|
|
2557
2561
|
|
|
2562
|
+
let fromDate = new Date( req.query.date );
|
|
2563
|
+
let toDate = new Date( req.query.date );
|
|
2564
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2565
|
+
const taskBaseMatch = {
|
|
2566
|
+
// eslint-disable-next-line camelcase
|
|
2567
|
+
// store_id,
|
|
2568
|
+
userId,
|
|
2569
|
+
scheduleStartTime_iso: { $lt: toDate },
|
|
2570
|
+
scheduleEndTime_iso: { $gte: fromDate },
|
|
2571
|
+
timeFlagStatus: true,
|
|
2572
|
+
...clientId,
|
|
2573
|
+
...storeMatch,
|
|
2574
|
+
};
|
|
2575
|
+
|
|
2576
|
+
console.log( 'taskBaseMatch =>', taskBaseMatch );
|
|
2577
|
+
const taskBuildPipeline = ( matchExtraConditions = {} ) => [
|
|
2578
|
+
{ $match: { ...taskBaseMatch, ...matchExtraConditions } },
|
|
2579
|
+
{
|
|
2580
|
+
$facet: {
|
|
2581
|
+
total: [ { $count: 'total' } ],
|
|
2582
|
+
toDo: [
|
|
2583
|
+
{ $match: { checklistStatus: 'open' } },
|
|
2584
|
+
{ $group: { _id: '', count: { $sum: 1 } } },
|
|
2585
|
+
],
|
|
2586
|
+
inprogress: [
|
|
2587
|
+
{ $match: { checklistStatus: 'inprogress' } },
|
|
2588
|
+
{ $group: { _id: '', count: { $sum: 1 } } },
|
|
2589
|
+
],
|
|
2590
|
+
submit: [
|
|
2591
|
+
{ $match: { checklistStatus: 'submit' } },
|
|
2592
|
+
{ $group: { _id: '', count: { $sum: 1 } } },
|
|
2593
|
+
],
|
|
2594
|
+
},
|
|
2595
|
+
},
|
|
2596
|
+
];
|
|
2597
|
+
|
|
2558
2598
|
const processResult = ( result ) => ( {
|
|
2559
2599
|
totalchecklist: result[0]?.total[0]?.total || 0,
|
|
2560
2600
|
todo: result[0]?.toDo[0]?.count || 0,
|
|
@@ -2563,7 +2603,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2563
2603
|
} );
|
|
2564
2604
|
|
|
2565
2605
|
const checklistQuery = buildPipeline( { checkListType: 'custom' } );
|
|
2566
|
-
const taskQuery =
|
|
2606
|
+
const taskQuery = taskBuildPipeline();
|
|
2567
2607
|
|
|
2568
2608
|
const [ checklistResult, taskResult ] = await Promise.allSettled( [
|
|
2569
2609
|
processedchecklist.aggregate( checklistQuery ),
|
|
@@ -2772,9 +2812,80 @@ export async function checklistv1( req, res ) {
|
|
|
2772
2812
|
return pipeline;
|
|
2773
2813
|
};
|
|
2774
2814
|
|
|
2815
|
+
let fromDate = new Date( req.query.date );
|
|
2816
|
+
let toDate = new Date( req.query.date );
|
|
2817
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2818
|
+
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
2819
|
+
const matchConditions = [
|
|
2820
|
+
// eslint-disable-next-line camelcase
|
|
2821
|
+
// { store_id },
|
|
2822
|
+
{ userId },
|
|
2823
|
+
{ scheduleStartTime_iso: { $lt: toDate } },
|
|
2824
|
+
{ scheduleEndTime_iso: { $gte: fromDate } },
|
|
2825
|
+
{ timeFlagStatus: true },
|
|
2826
|
+
...matchExtraConditions,
|
|
2827
|
+
clientId,
|
|
2828
|
+
storeMatch,
|
|
2829
|
+
];
|
|
2830
|
+
if ( checklistStatus ) {
|
|
2831
|
+
matchConditions.push( { checklistStatus } );
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
const pipeline = [
|
|
2835
|
+
{ $match: { $and: matchConditions } },
|
|
2836
|
+
...( searchValue ?
|
|
2837
|
+
[ { $match: { $or: [ { checkListName: { $regex: searchValue, $options: 'i' } } ] } } ] :
|
|
2838
|
+
[] ),
|
|
2839
|
+
{
|
|
2840
|
+
$project: {
|
|
2841
|
+
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
2842
|
+
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
2843
|
+
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
2844
|
+
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
2845
|
+
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
2846
|
+
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
2847
|
+
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
2848
|
+
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
2849
|
+
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
2850
|
+
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
2851
|
+
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
2852
|
+
allowedStoreLocation: {
|
|
2853
|
+
$cond: {
|
|
2854
|
+
if: { $eq: [ '$client_id', '11' ] },
|
|
2855
|
+
then: false,
|
|
2856
|
+
else: {
|
|
2857
|
+
'$cond': {
|
|
2858
|
+
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
2859
|
+
'then': false,
|
|
2860
|
+
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
2861
|
+
},
|
|
2862
|
+
},
|
|
2863
|
+
},
|
|
2864
|
+
},
|
|
2865
|
+
reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
|
|
2866
|
+
startTime_string: { $ifNull: [ '$startTime_string', '' ] },
|
|
2867
|
+
submitTime_string: { $ifNull: [ '$submitTime_string', '' ] },
|
|
2868
|
+
timeFlag: { $ifNull: [ '$timeFlag', '' ] },
|
|
2869
|
+
scheduleRepeatedType: { $ifNull: [ '$scheduleRepeatedType', '' ] },
|
|
2870
|
+
timeDifference: { $subtract: [ '$scheduleEndTime_iso', '$date_iso' ] },
|
|
2871
|
+
redoStatus: { $ifNull: [ '$redoStatus', false ] },
|
|
2872
|
+
type: { $ifNull: [ '$checkListType', '' ] },
|
|
2873
|
+
priorityType: { $ifNull: [ '$priorityType', '' ] },
|
|
2874
|
+
...projectExtraConditions,
|
|
2875
|
+
client_id: { $ifNull: [ '$client_id', '' ] },
|
|
2876
|
+
coverage: { $ifNull: [ '$coverage', '' ] },
|
|
2877
|
+
taskType: { $ifNull: [ '$planoType', '' ] },
|
|
2878
|
+
streamId: { $ifNull: [ '$streamId', '' ] },
|
|
2879
|
+
},
|
|
2880
|
+
},
|
|
2881
|
+
];
|
|
2882
|
+
|
|
2883
|
+
return pipeline;
|
|
2884
|
+
};
|
|
2885
|
+
|
|
2775
2886
|
const [ checklistResult, taskResult ] = await Promise.allSettled( [
|
|
2776
2887
|
processedchecklist.aggregate( buildPipeline( [ { checkListType: 'custom' } ], { isPlano: 1, planoId: 1, planoType: 1, floorId: 1 } ) ),
|
|
2777
|
-
processedTask.aggregate(
|
|
2888
|
+
processedTask.aggregate( taskBuildPipeline( [], { isPlano: 1, planoId: 1, planoType: 1, floorId: 1 } ) ),
|
|
2778
2889
|
] );
|
|
2779
2890
|
|
|
2780
2891
|
const checklistData = checklistResult.status === 'fulfilled' ? checklistResult.value : [];
|
|
@@ -402,8 +402,7 @@ export const getConfigDetails = async ( req, res ) => {
|
|
|
402
402
|
checkListId: storechecklistdetails._id,
|
|
403
403
|
isdeleted: false,
|
|
404
404
|
};
|
|
405
|
-
let
|
|
406
|
-
let questionDetails = await questionService.findSort( query, {}, sectionSort );
|
|
405
|
+
let questionDetails = await questionService.find( query );
|
|
407
406
|
if ( questionDetails.length ) {
|
|
408
407
|
let sections = [];
|
|
409
408
|
let bucket = JSON.parse( process.env.BUCKET );
|
|
@@ -739,7 +738,7 @@ export const duplicateChecklist = async ( req, res ) => {
|
|
|
739
738
|
}
|
|
740
739
|
await assignedService.insertMany( users );
|
|
741
740
|
}
|
|
742
|
-
let sectionList = await questionService.
|
|
741
|
+
let sectionList = await questionService.find( { checkListId: checkDetails._id, client_id: req.query.clientId, isdeleted: false } );
|
|
743
742
|
if ( sectionList.length ) {
|
|
744
743
|
let sections= [];
|
|
745
744
|
for ( let i = 0; i < sectionList.length; i++ ) {
|
|
@@ -811,7 +810,7 @@ export const update = async ( req, res ) => {
|
|
|
811
810
|
return res.sendError( 'no data found', 204 );
|
|
812
811
|
}
|
|
813
812
|
|
|
814
|
-
let getExistQuestions = await questionService.
|
|
813
|
+
let getExistQuestions = await questionService.find( { checkListId: req.params.checklistId, client_id: req.body.clientId } );
|
|
815
814
|
|
|
816
815
|
inputBody.sections.forEach( async ( element ) => {
|
|
817
816
|
if ( !element.questions.length && inputBody.submitType == 'configure' ) {
|
|
@@ -2970,11 +2969,6 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
|
|
|
2970
2969
|
isdeleted: false,
|
|
2971
2970
|
},
|
|
2972
2971
|
} );
|
|
2973
|
-
sectionQuery.push( {
|
|
2974
|
-
$sort: {
|
|
2975
|
-
sectionNumber: 1,
|
|
2976
|
-
},
|
|
2977
|
-
} );
|
|
2978
2972
|
let getSections = await questionService.aggregate( sectionQuery );
|
|
2979
2973
|
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection' ].includes( getCLconfig.checkListType ) ) {
|
|
2980
2974
|
if ( getSections.length ) {
|
|
@@ -2984,7 +2978,6 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
|
|
|
2984
2978
|
collectQuestions.sectionName = element3.section;
|
|
2985
2979
|
collectQuestions.sectionOldName = element3.sectionOldName;
|
|
2986
2980
|
collectQuestions.questions = element3.question;
|
|
2987
|
-
collectQuestions.sectionNumber = element3.sectionNumber || 0;
|
|
2988
2981
|
collectSections.push( collectQuestions );
|
|
2989
2982
|
}
|
|
2990
2983
|
}
|
|
@@ -728,7 +728,6 @@ export const userPerformance = async ( req, res ) => {
|
|
|
728
728
|
userEmail: 1,
|
|
729
729
|
userName: 1,
|
|
730
730
|
questionCount: 1,
|
|
731
|
-
redoStatus: 1,
|
|
732
731
|
},
|
|
733
732
|
} );
|
|
734
733
|
|
|
@@ -746,7 +745,6 @@ export const userPerformance = async ( req, res ) => {
|
|
|
746
745
|
submittedChecklistQuestionCount: {
|
|
747
746
|
$sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] },
|
|
748
747
|
},
|
|
749
|
-
redo: { $sum: { $cond: [ { $eq: [ '$redoStatus', true ] }, 1, 0 ] } },
|
|
750
748
|
},
|
|
751
749
|
} );
|
|
752
750
|
|
|
@@ -818,7 +816,6 @@ export const userPerformance = async ( req, res ) => {
|
|
|
818
816
|
'Email': element.userEmail || '--',
|
|
819
817
|
'Checklist Assigned': element.checkListCount || '--',
|
|
820
818
|
'Flags': element.flaggedCount || '--',
|
|
821
|
-
'ReDo': element.redo || '--',
|
|
822
819
|
'Completion %': element.completion || '--',
|
|
823
820
|
'Compliance %': element.compliance || '--',
|
|
824
821
|
'Performance %': element.performance || '--',
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { getchecklist, viewchecklist, getMobileUseagelist, storeOpencloselist, getcustomerunattendedlist,
|
|
4
4
|
storesList, checklistDropdown, redoChecklist, redomultiChecklist, approveChecklist,
|
|
5
|
-
approvalstatus, getLogs, headerStoresV2, teamsList, userList, checkNotificationCount } from '../controllers/gallery.controller.js';
|
|
5
|
+
approvalstatus, getLogs, headerStoresV2, teamsList, userList, checkNotificationCount, vehicleCheckInUpdate } from '../controllers/gallery.controller.js';
|
|
6
6
|
import express from 'express';
|
|
7
7
|
export const galleryRouter = express.Router();
|
|
8
8
|
import { validate, isAllowedSessionHandler, isAllowedClient, getAssinedStore } from 'tango-app-api-middleware';
|
|
@@ -32,4 +32,5 @@ galleryRouter
|
|
|
32
32
|
.post( '/headerStores_v2', isAllowedSessionHandler, isAllowedClient, validate( validationDtos.validateHeaderParamsv2 ), getAssinedStore, headerStoresV2 )
|
|
33
33
|
.get( '/teamsList', isAllowedSessionHandler, isAllowedClient, teamsList )
|
|
34
34
|
.post( '/userList', isAllowedSessionHandler, isAllowedClient, userList )
|
|
35
|
-
.post( '/checkNotificationCount', isAllowedSessionHandler, getAssinedStore, checkNotificationCount )
|
|
35
|
+
.post( '/checkNotificationCount', isAllowedSessionHandler, getAssinedStore, checkNotificationCount )
|
|
36
|
+
.post( '/vehicleCheckInUpdate', isAllowedSessionHandler, vehicleCheckInUpdate );
|
|
@@ -24,7 +24,6 @@ internalTraxRouter
|
|
|
24
24
|
.post( '/sendPushNotification', isAllowedInternalAPIHandler, internalController.internalSendPushNotification )
|
|
25
25
|
.post( '/sendAiPushNotification', isAllowedInternalAPIHandler, internalController.internalAISendPushNotification )
|
|
26
26
|
.post( '/getLiveChecklistClients', isAllowedInternalAPIHandler, internalController.getLiveChecklistClients )
|
|
27
|
-
.post( '/notificationCreate', isAllowedInternalAPIHandler, internalController.notificationCreate )
|
|
28
|
-
.post( '/insertAINotification', isAllowedInternalAPIHandler, internalController.insertAINotification );
|
|
27
|
+
.post( '/notificationCreate', isAllowedInternalAPIHandler, internalController.notificationCreate );
|
|
29
28
|
|
|
30
29
|
|
|
@@ -28,8 +28,4 @@ export const aggregate = async ( query = {} ) => {
|
|
|
28
28
|
return model.checklistquestionconfigModel.aggregate( query );
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const findSort = async ( query={}, field={}, sort = {} ) => {
|
|
32
|
-
return model.checklistquestionconfigModel.find( query, field ).sort( sort );
|
|
33
|
-
};
|
|
34
|
-
|
|
35
31
|
|