tango-app-api-trax 3.6.0-task-3 → 3.6.0-task-4

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-task-3",
3
+ "version": "3.6.0-task-4",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -18,11 +18,6 @@ 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 );
26
21
  let name;
27
22
  let fileType = requestData?.fileType || 'pdfzip';
28
23
 
@@ -44,55 +39,60 @@ export const downloadInsert = async ( req, res ) => {
44
39
  }
45
40
  }
46
41
  // console.log( requestData );
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
- }
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
+ // }
96
96
 
97
97
  if ( requestData.fileType == 'pdf' ) {
98
98
  if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
@@ -295,6 +295,11 @@ export async function PCLconfigCreation( req, res ) {
295
295
  isdeleted: false,
296
296
  },
297
297
  } );
298
+ sectionQuery.push( {
299
+ $sort: {
300
+ sectionNumber: 1,
301
+ },
302
+ } );
298
303
  let getSections = await CLquestions.aggregate( sectionQuery );
299
304
  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 ) ) {
300
305
  if ( getSections.length ) {
@@ -302,7 +307,9 @@ export async function PCLconfigCreation( req, res ) {
302
307
  let collectQuestions = {};
303
308
  collectQuestions.section_id = element3._id;
304
309
  collectQuestions.sectionName = element3.section;
310
+ collectQuestions.sectionOldName = element3.sectionOldName || '';
305
311
  collectQuestions.questions = element3.question;
312
+ collectQuestions.sectionNumber = element3.sectionNumber|| '';
306
313
  collectSections.push( collectQuestions );
307
314
  }
308
315
  }
@@ -863,6 +870,11 @@ async function insertData( requestData ) {
863
870
  isdeleted: false,
864
871
  },
865
872
  } );
873
+ sectionQuery.push( {
874
+ $sort: {
875
+ sectionNumber: 1,
876
+ },
877
+ } );
866
878
  let getSections = await CLquestions.aggregate( sectionQuery );
867
879
  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 ) ) {
868
880
  if ( getSections.length ) {
@@ -2462,3 +2474,43 @@ export async function storecheckExists( data ) {
2462
2474
  logger.error( { error: error, function: 'internalAISendPushNotification' } );
2463
2475
  }
2464
2476
  }
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
+ }
@@ -155,15 +155,19 @@ export async function startChecklist( req, res ) {
155
155
 
156
156
  let updateData = {};
157
157
  let currentDateTime;
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 } );
158
+ if ( getBeforeChecklist[0]?.store_id && getBeforeChecklist[0]?.store_id != '' ) {
159
+ let storeTimeZone = await storeService.findOne( { storeId: getBeforeChecklist[0].store_id, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
160
160
  if ( storeTimeZone?.storeProfile?.timeZone ) {
161
161
  currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
162
162
  } else {
163
163
  currentDateTime = dayjs();
164
164
  }
165
165
  } else {
166
- currentDateTime = dayjs();
166
+ if ( requestData.currentTime && requestData.currentTime !='' ) {
167
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
168
+ } else {
169
+ currentDateTime = dayjs();
170
+ }
167
171
  }
168
172
  updateData.checklistStatus = 'inprogress';
169
173
  updateData.startMobileTime = requestData?.currentTime;
@@ -347,13 +351,29 @@ export async function startTask( req, res ) {
347
351
  }
348
352
  }
349
353
 
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();
354
+ // const storeTimeZone = await storeService.findOne(
355
+ // { storeName: task.storeName },
356
+ // { 'storeProfile.timeZone': 1 },
357
+ // );
358
+ // const currentDateTime = storeTimeZone?.storeProfile?.timeZone ?
359
+ // dayjs().tz( storeTimeZone.storeProfile.timeZone ) :
360
+ // dayjs();
361
+
362
+ let currentDateTime;
363
+ if ( getBeforeTask[0].storeName && getBeforeTask[0].storeName!='' ) {
364
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeTask[0].storeName, $options: 'i' }, clientId: getBeforeTask[0].client_id }, { 'storeProfile.timeZone': 1 } );
365
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
366
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
367
+ } else {
368
+ currentDateTime = dayjs();
369
+ }
370
+ } else {
371
+ if ( requestData.currentTime && requestData.currentTime !='' ) {
372
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
373
+ } else {
374
+ currentDateTime = dayjs();
375
+ }
376
+ }
357
377
 
358
378
 
359
379
  let updatedNewData;
@@ -1804,8 +1824,8 @@ export async function submitChecklist( req, res ) {
1804
1824
 
1805
1825
  let currentDateTime;
1806
1826
  let storeTimeZone;
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 } );
1827
+ if ( getchecklist[0]?.store_id && getchecklist[0]?.store_id !='' ) {
1828
+ storeTimeZone = await storeService.findOne( { storeId: getchecklist[0].store_id, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
1809
1829
  if ( storeTimeZone?.storeProfile?.timeZone ) {
1810
1830
  currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1811
1831
  } else {
@@ -402,7 +402,8 @@ export const getConfigDetails = async ( req, res ) => {
402
402
  checkListId: storechecklistdetails._id,
403
403
  isdeleted: false,
404
404
  };
405
- let questionDetails = await questionService.find( query );
405
+ let sectionSort = { sectionNumber: 1 };
406
+ let questionDetails = await questionService.findSort( query, {}, sectionSort );
406
407
  if ( questionDetails.length ) {
407
408
  let sections = [];
408
409
  let bucket = JSON.parse( process.env.BUCKET );
@@ -738,7 +739,7 @@ export const duplicateChecklist = async ( req, res ) => {
738
739
  }
739
740
  await assignedService.insertMany( users );
740
741
  }
741
- let sectionList = await questionService.find( { checkListId: checkDetails._id, client_id: req.query.clientId, isdeleted: false } );
742
+ let sectionList = await questionService.findSort( { checkListId: checkDetails._id, client_id: req.query.clientId, isdeleted: false }, {}, { sectionNumber: 1 } );
742
743
  if ( sectionList.length ) {
743
744
  let sections= [];
744
745
  for ( let i = 0; i < sectionList.length; i++ ) {
@@ -810,7 +811,7 @@ export const update = async ( req, res ) => {
810
811
  return res.sendError( 'no data found', 204 );
811
812
  }
812
813
 
813
- let getExistQuestions = await questionService.find( { checkListId: req.params.checklistId, client_id: req.body.clientId } );
814
+ let getExistQuestions = await questionService.findSort( { checkListId: req.params.checklistId, client_id: req.body.clientId }, {}, { sectionNumber: 1 } );
814
815
 
815
816
  inputBody.sections.forEach( async ( element ) => {
816
817
  if ( !element.questions.length && inputBody.submitType == 'configure' ) {
@@ -2969,6 +2970,11 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
2969
2970
  isdeleted: false,
2970
2971
  },
2971
2972
  } );
2973
+ sectionQuery.push( {
2974
+ $sort: {
2975
+ sectionNumber: 1,
2976
+ },
2977
+ } );
2972
2978
  let getSections = await questionService.aggregate( sectionQuery );
2973
2979
  if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection' ].includes( getCLconfig.checkListType ) ) {
2974
2980
  if ( getSections.length ) {
@@ -2978,6 +2984,7 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
2978
2984
  collectQuestions.sectionName = element3.section;
2979
2985
  collectQuestions.sectionOldName = element3.sectionOldName;
2980
2986
  collectQuestions.questions = element3.question;
2987
+ collectQuestions.sectionNumber = element3.sectionNumber || 0;
2981
2988
  collectSections.push( collectQuestions );
2982
2989
  }
2983
2990
  }
@@ -728,6 +728,7 @@ export const userPerformance = async ( req, res ) => {
728
728
  userEmail: 1,
729
729
  userName: 1,
730
730
  questionCount: 1,
731
+ redoStatus: 1,
731
732
  },
732
733
  } );
733
734
 
@@ -745,6 +746,7 @@ export const userPerformance = async ( req, res ) => {
745
746
  submittedChecklistQuestionCount: {
746
747
  $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] },
747
748
  },
749
+ redo: { $sum: { $cond: [ { $eq: [ '$redoStatus', true ] }, 1, 0 ] } },
748
750
  },
749
751
  } );
750
752
 
@@ -816,6 +818,7 @@ export const userPerformance = async ( req, res ) => {
816
818
  'Email': element.userEmail || '--',
817
819
  'Checklist Assigned': element.checkListCount || '--',
818
820
  'Flags': element.flaggedCount || '--',
821
+ 'ReDo': element.redo || '--',
819
822
  'Completion %': element.completion || '--',
820
823
  'Compliance %': element.compliance || '--',
821
824
  'Performance %': element.performance || '--',
@@ -1694,7 +1697,7 @@ export const checklistInfo = async ( req, res ) => {
1694
1697
  exportdata.push( {
1695
1698
  'Date': element.date_string || '--',
1696
1699
  'Store Name': element.storeName || '--',
1697
- 'Checklist Owner': element.userName || '--',
1700
+ 'User Name': element.userName || '--',
1698
1701
  'Status': element.checklistStatus || '--',
1699
1702
  'Submitted By': element.userName || '--',
1700
1703
  'Submitted On': element.submitTime_string || '--',
@@ -1705,7 +1708,7 @@ export const checklistInfo = async ( req, res ) => {
1705
1708
  } else if ( requestData.groupByType==='Store' ) {
1706
1709
  exportdata.push( {
1707
1710
  'CheckList Name': element.checkListName || '--',
1708
- 'Checklist Owner': element.userName || '--',
1711
+ 'User Name': element.userName || '--',
1709
1712
  'Status': element.checklistStatus || '--',
1710
1713
  'Submitted By': element.userName || '--',
1711
1714
  'Submitted On': element.submitTime_string || '--',
@@ -1719,7 +1722,7 @@ export const checklistInfo = async ( req, res ) => {
1719
1722
  'Date': element.date_string || '--',
1720
1723
  'CheckList Name': element.checkListName || '--',
1721
1724
  'Store Name': element.storeName || '--',
1722
- 'Checklist Owner': element.userName || '--',
1725
+ 'User Name': element.userName || '--',
1723
1726
  'Status': element.checklistStatus || '--',
1724
1727
  'Submitted On': element.submitTime_string || '--',
1725
1728
  'Flags': element.flaggedChecklist || '--',
@@ -24,6 +24,7 @@ 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 );
27
+ .post( '/notificationCreate', isAllowedInternalAPIHandler, internalController.notificationCreate )
28
+ .post( '/insertAINotification', isAllowedInternalAPIHandler, internalController.insertAINotification );
28
29
 
29
30
 
@@ -28,4 +28,8 @@ 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
+
31
35