tango-app-api-trax 3.6.0-sec-10 → 3.6.0-task-1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.6.0-sec-10",
3
+ "version": "3.6.0-task-1",
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.142",
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
- // // No Need to Check
43
- // let fromDate = new Date( requestData.fromDate );
44
- // let toDate = new Date( requestData.toDate );
45
- // let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
46
- // toDate = new Date( toDate.getTime() - userTimezoneOffset );
47
- // toDate.setUTCHours( 23, 59, 59, 59 );
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.length > 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
- // }
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,13 +295,6 @@ export async function PCLconfigCreation( req, res ) {
295
295
  isdeleted: false,
296
296
  },
297
297
  } );
298
-
299
- sectionQuery.push( {
300
- $sort: {
301
- sectionNumber: 1,
302
- },
303
- } );
304
-
305
298
  let getSections = await CLquestions.aggregate( sectionQuery );
306
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 ) ) {
307
300
  if ( getSections.length ) {
@@ -309,9 +302,7 @@ export async function PCLconfigCreation( req, res ) {
309
302
  let collectQuestions = {};
310
303
  collectQuestions.section_id = element3._id;
311
304
  collectQuestions.sectionName = element3.section;
312
- collectQuestions.sectionOldName = element3.sectionOldName || '';
313
305
  collectQuestions.questions = element3.question;
314
- collectQuestions.sectionNumber = element3.sectionNumber|| '';
315
306
  collectSections.push( collectQuestions );
316
307
  }
317
308
  }
@@ -2471,43 +2462,3 @@ export async function storecheckExists( data ) {
2471
2462
  logger.error( { error: error, function: 'internalAISendPushNotification' } );
2472
2463
  }
2473
2464
  }
2474
-
2475
- export async function insertAINotification( req, res ) {
2476
- try {
2477
- let requestData = req.body;
2478
- let insertData= [];
2479
- let findAllUser = await userService.find( { clientId: requestData.clientId, isActive: true } );
2480
- for ( let user of findAllUser ) {
2481
- let data= {};
2482
- data.userId = user._id;
2483
- data.storeId = requestData.storeId;
2484
- data.storeName = requestData.storeName;
2485
- data.captureTime = requestData.captureTime;
2486
- data.clientId = requestData.clientId;
2487
- data.sourceCheckList_id = requestData.sourceCheckList_id;
2488
- data.checkListName = requestData.checkListName;
2489
- data.notificationType = requestData.notificationType;
2490
- let payload = {
2491
- userType: user.userType,
2492
- role: user.role,
2493
- assignedStores: user.assignedStores,
2494
- clientId: user.clientId,
2495
- email: user.email,
2496
- };
2497
- let result = await storecheckExists( payload );
2498
- if ( result ) {
2499
- insertData.push( data );
2500
- }
2501
- }
2502
- // console.log( 'insertData =>', insertData );
2503
- let create = await notificationModel.insertManynotificationModel( insertData );
2504
- // console.log( 'create =>', create );
2505
- if ( create ) {
2506
- return res.sendSuccess( 'updated successfully' );
2507
- }
2508
- } catch ( e ) {
2509
- logger.error( { error: e, function: 'insertAINotification' } );
2510
- if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
2511
- else res.sendError( e, 500 );
2512
- }
2513
- }
@@ -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 userTask = await processedTask.find( { userId: req.user._id, userEmail: req.user.email, date_string: dayjs( req.query.date ).format( 'YYYY-MM-DD' ) }, { store_id: 1, storeName: 1 } );
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]?.store_id && getBeforeChecklist[0]?.store_id != '' ) {
155
- let storeTimeZone = await storeService.findOne( { storeId: getBeforeChecklist[0].store_id, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
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
- if ( requestData.currentTime && requestData.currentTime !='' ) {
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
- // 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();
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
- let currentDateTime;
359
- if ( getBeforeTask[0].storeName && getBeforeTask[0].storeName!='' ) {
360
- let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeTask[0].storeName, $options: 'i' }, clientId: getBeforeTask[0].client_id }, { 'storeProfile.timeZone': 1 } );
361
- if ( storeTimeZone?.storeProfile?.timeZone ) {
362
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
363
- } else {
364
- currentDateTime = dayjs();
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
- if ( requestData.currentTime && requestData.currentTime !='' ) {
368
- currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
369
- } else {
370
- currentDateTime = dayjs();
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
- const bucket = JSON.parse( process.env.BUCKET );
433
- await Promise.all(
434
- getUpdatedTask[0].questionAnswers.map( ( section ) =>
435
- section.questions.map( async ( question ) => {
436
- if ( question.questionReferenceImage.length > 0 ) {
437
- question.questionReferenceImage = await Promise.all(
438
- question.questionReferenceImage.map( async ( image ) => {
439
- return await signedUrl( {
440
- Bucket: bucket.sop,
441
- file_path: decodeURIComponent( image ),
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
- await Promise.all(
448
- question.answers.map( async ( answer ) => {
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,
@@ -611,47 +612,47 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
611
612
  return res.sendError( 'Please Fill all Required Fields', 400 );
612
613
  }
613
614
 
614
- // if ( requestData.submittype == 'submit' ) {
615
- let reqAnswers = requestData.questionAnswers;
616
- logger.error( { functionName: 'payload', message: reqAnswers } );
617
- let CLQAnswers = getChecklistQA.questionAnswers;
618
- logger.error( { functionName: 'CLQAnswers', message: CLQAnswers } );
619
- let validationCount= 0;
620
- let errorCount = 0;
621
- CLQAnswers.forEach( ( section ) => {
622
- let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
623
- if ( requestSection.length ) {
624
- requestSection.forEach( ( item ) => item.section_id = section.section_id );
625
- section.questions.forEach( ( question ) => {
626
- // question.answers.forEach( ( answer ) => {
627
- let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
628
- if ( sectionQuestion.length ) {
629
- if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
630
- validationCount++;
631
- } else {
632
- if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
615
+ if ( requestData.submittype == 'submit' ) {
616
+ let reqAnswers = requestData.questionAnswers;
617
+ logger.error( { functionName: 'payload', message: reqAnswers } );
618
+ let CLQAnswers = getChecklistQA.questionAnswers;
619
+ logger.error( { functionName: 'CLQAnswers', message: CLQAnswers } );
620
+ let validationCount= 0;
621
+ let errorCount = 0;
622
+ CLQAnswers.forEach( ( section ) => {
623
+ let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
624
+ if ( requestSection.length ) {
625
+ requestSection.forEach( ( item ) => item.section_id = section.section_id );
626
+ section.questions.forEach( ( question ) => {
627
+ // question.answers.forEach( ( answer ) => {
628
+ let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
629
+ if ( sectionQuestion.length ) {
630
+ if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
633
631
  validationCount++;
632
+ } else {
633
+ if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
634
+ validationCount++;
635
+ }
634
636
  }
637
+ } else {
638
+ errorCount++;
635
639
  }
636
- } else {
637
- errorCount++;
638
- }
639
- // } );
640
- } );
640
+ // } );
641
+ } );
642
+ } else {
643
+ errorCount++;
644
+ }
645
+ } );
646
+ if ( validationCount ) {
647
+ return res.sendError( 'Please Fill all Required Fields', 400 );
648
+ } else if ( errorCount ) {
649
+ return res.sendError( 'Checklist got edited.please contact admin', 400 );
641
650
  } else {
642
- errorCount++;
651
+ next();
643
652
  }
644
- } );
645
- if ( validationCount && requestData.submittype == 'submit' ) {
646
- return res.sendError( 'Please Fill all Required Fields', 400 );
647
- } else if ( errorCount && !requestData?.editSubmit ) {
648
- return res.sendError( 'Checklist got edited.please contact admin', 400 );
649
653
  } else {
650
654
  next();
651
655
  }
652
- // } else {
653
- // next();
654
- // }
655
656
  } catch ( e ) {
656
657
  logger.error( { function: 'sopMobilechecklistQuestionValidator', error: e, body: req.body } );
657
658
  return res.sendError( e, 500 );
@@ -1803,8 +1804,8 @@ export async function submitChecklist( req, res ) {
1803
1804
 
1804
1805
  let currentDateTime;
1805
1806
  let storeTimeZone;
1806
- if ( getchecklist[0]?.store_id && getchecklist[0]?.store_id !='' ) {
1807
- storeTimeZone = await storeService.findOne( { storeId: getchecklist[0].store_id, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
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 {
@@ -2555,6 +2556,42 @@ export async function dashboardv1( req, res ) {
2555
2556
  },
2556
2557
  ];
2557
2558
 
2559
+ let fromDate = new Date( req.query.date );
2560
+ let toDate = new Date( req.query.date );
2561
+ toDate.setDate( toDate.getDate() + 1 );
2562
+ const taskBaseMatch = {
2563
+ // eslint-disable-next-line camelcase
2564
+ // store_id,
2565
+ userId,
2566
+ scheduleStartTime_iso: { $lt: toDate },
2567
+ scheduleEndTime_iso: { $gte: fromDate },
2568
+ timeFlagStatus: true,
2569
+ ...clientId,
2570
+ ...storeMatch,
2571
+ };
2572
+
2573
+ console.log( 'taskBaseMatch =>', taskBaseMatch );
2574
+ const taskBuildPipeline = ( matchExtraConditions = {} ) => [
2575
+ { $match: { ...taskBaseMatch, ...matchExtraConditions } },
2576
+ {
2577
+ $facet: {
2578
+ total: [ { $count: 'total' } ],
2579
+ toDo: [
2580
+ { $match: { checklistStatus: 'open' } },
2581
+ { $group: { _id: '', count: { $sum: 1 } } },
2582
+ ],
2583
+ inprogress: [
2584
+ { $match: { checklistStatus: 'inprogress' } },
2585
+ { $group: { _id: '', count: { $sum: 1 } } },
2586
+ ],
2587
+ submit: [
2588
+ { $match: { checklistStatus: 'submit' } },
2589
+ { $group: { _id: '', count: { $sum: 1 } } },
2590
+ ],
2591
+ },
2592
+ },
2593
+ ];
2594
+
2558
2595
  const processResult = ( result ) => ( {
2559
2596
  totalchecklist: result[0]?.total[0]?.total || 0,
2560
2597
  todo: result[0]?.toDo[0]?.count || 0,
@@ -2563,7 +2600,7 @@ export async function dashboardv1( req, res ) {
2563
2600
  } );
2564
2601
 
2565
2602
  const checklistQuery = buildPipeline( { checkListType: 'custom' } );
2566
- const taskQuery = buildPipeline();
2603
+ const taskQuery = taskBuildPipeline();
2567
2604
 
2568
2605
  const [ checklistResult, taskResult ] = await Promise.allSettled( [
2569
2606
  processedchecklist.aggregate( checklistQuery ),
@@ -2772,9 +2809,80 @@ export async function checklistv1( req, res ) {
2772
2809
  return pipeline;
2773
2810
  };
2774
2811
 
2812
+ let fromDate = new Date( req.query.date );
2813
+ let toDate = new Date( req.query.date );
2814
+ toDate.setDate( toDate.getDate() + 1 );
2815
+ const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
2816
+ const matchConditions = [
2817
+ // eslint-disable-next-line camelcase
2818
+ // { store_id },
2819
+ { userId },
2820
+ { scheduleStartTime_iso: { $lt: toDate } },
2821
+ { scheduleEndTime_iso: { $gte: fromDate } },
2822
+ { timeFlagStatus: true },
2823
+ ...matchExtraConditions,
2824
+ clientId,
2825
+ storeMatch,
2826
+ ];
2827
+ if ( checklistStatus ) {
2828
+ matchConditions.push( { checklistStatus } );
2829
+ }
2830
+
2831
+ const pipeline = [
2832
+ { $match: { $and: matchConditions } },
2833
+ ...( searchValue ?
2834
+ [ { $match: { $or: [ { checkListName: { $regex: searchValue, $options: 'i' } } ] } } ] :
2835
+ [] ),
2836
+ {
2837
+ $project: {
2838
+ checkListName: { $ifNull: [ '$checkListName', '' ] },
2839
+ scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
2840
+ scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
2841
+ scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
2842
+ scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
2843
+ checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
2844
+ checkListId: { $ifNull: [ '$checkListId', '' ] },
2845
+ startTime: { $ifNull: [ '$startTime', '' ] },
2846
+ submitTime: { $ifNull: [ '$submitTime', '' ] },
2847
+ allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
2848
+ // allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2849
+ allowedStoreLocation: {
2850
+ $cond: {
2851
+ if: { $eq: [ '$client_id', '11' ] },
2852
+ then: false,
2853
+ else: {
2854
+ '$cond': {
2855
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2856
+ 'then': false,
2857
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2858
+ },
2859
+ },
2860
+ },
2861
+ },
2862
+ reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
2863
+ startTime_string: { $ifNull: [ '$startTime_string', '' ] },
2864
+ submitTime_string: { $ifNull: [ '$submitTime_string', '' ] },
2865
+ timeFlag: { $ifNull: [ '$timeFlag', '' ] },
2866
+ scheduleRepeatedType: { $ifNull: [ '$scheduleRepeatedType', '' ] },
2867
+ timeDifference: { $subtract: [ '$scheduleEndTime_iso', '$date_iso' ] },
2868
+ redoStatus: { $ifNull: [ '$redoStatus', false ] },
2869
+ type: { $ifNull: [ '$checkListType', '' ] },
2870
+ priorityType: { $ifNull: [ '$priorityType', '' ] },
2871
+ ...projectExtraConditions,
2872
+ client_id: { $ifNull: [ '$client_id', '' ] },
2873
+ coverage: { $ifNull: [ '$coverage', '' ] },
2874
+ taskType: { $ifNull: [ '$planoType', '' ] },
2875
+ streamId: { $ifNull: [ '$streamId', '' ] },
2876
+ },
2877
+ },
2878
+ ];
2879
+
2880
+ return pipeline;
2881
+ };
2882
+
2775
2883
  const [ checklistResult, taskResult ] = await Promise.allSettled( [
2776
2884
  processedchecklist.aggregate( buildPipeline( [ { checkListType: 'custom' } ], { isPlano: 1, planoId: 1, planoType: 1, floorId: 1 } ) ),
2777
- processedTask.aggregate( buildPipeline( [], { isPlano: 1, planoId: 1, planoType: 1, floorId: 1 } ) ),
2885
+ processedTask.aggregate( taskBuildPipeline( [], { isPlano: 1, planoId: 1, planoType: 1, floorId: 1 } ) ),
2778
2886
  ] );
2779
2887
 
2780
2888
  const checklistData = checklistResult.status === 'fulfilled' ? checklistResult.value : [];
@@ -2969,11 +2969,6 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
2969
2969
  isdeleted: false,
2970
2970
  },
2971
2971
  } );
2972
- sectionQuery.push( {
2973
- $sort: {
2974
- sectionNumber: 1,
2975
- },
2976
- } );
2977
2972
  let getSections = await questionService.aggregate( sectionQuery );
2978
2973
  if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection' ].includes( getCLconfig.checkListType ) ) {
2979
2974
  if ( getSections.length ) {
@@ -2983,7 +2978,6 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
2983
2978
  collectQuestions.sectionName = element3.section;
2984
2979
  collectQuestions.sectionOldName = element3.sectionOldName;
2985
2980
  collectQuestions.questions = element3.question;
2986
- collectQuestions.sectionNumber = element3.sectionNumber || 0;
2987
2981
  collectSections.push( collectQuestions );
2988
2982
  }
2989
2983
  }
@@ -3725,7 +3719,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3725
3719
  await processedchecklist.deleteMany( { date_string: insertdata.date_string,
3726
3720
  date_iso: insertdata.date_iso,
3727
3721
  client_id: insertdata.client_id,
3728
- checkListId: updatedchecklist._id, checklistStatus: 'open', redoStatus: false } );
3722
+ checkListId: updatedchecklist._id, checklistStatus: 'open' } );
3729
3723
 
3730
3724
 
3731
3725
  let actionType = 'deleteOpenUsers';
@@ -3739,18 +3733,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3739
3733
  date_iso: insertdata.date_iso,
3740
3734
  client_id: insertdata.client_id,
3741
3735
  checkListId: updatedchecklist._id,
3742
- // checklistStatus: 'inprogress',
3743
- $or: [
3744
- {
3745
- $and: [
3746
- { checklistStatus: 'open' },
3747
- { redoStatus: true },
3748
- ],
3749
- },
3750
- {
3751
- checklistStatus: 'inprogress',
3752
- },
3753
- ],
3736
+ checklistStatus: 'inprogress',
3754
3737
  }, { userId: 1, store_id: 1 } );
3755
3738
 
3756
3739
  if ( inprogressData.length ) {
@@ -3769,7 +3752,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3769
3752
  }
3770
3753
 
3771
3754
  if ( deletedList.length ) {
3772
- await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, _id: { $in: deletedList }, redoStatus: false } );
3755
+ await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, _id: { $in: deletedList } } );
3773
3756
  }
3774
3757
  await processedchecklist.insertMany( assignUserList );
3775
3758
  actionType = 'insertAssignUsers';
@@ -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