tango-app-api-task 1.0.0-beta.1 → 1.0.0-beta.11

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-task",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,8 +24,8 @@
24
24
  "mongodb": "^6.10.0",
25
25
  "nodemon": "^3.1.7",
26
26
  "npm": "^10.9.2",
27
- "tango-api-schema": "^2.2.2",
28
- "tango-app-api-middleware": "^3.1.43-alpha.10",
27
+ "tango-api-schema": "2.2.5",
28
+ "tango-app-api-middleware": "3.1.43-alpha.10",
29
29
  "winston": "^3.17.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -83,13 +83,15 @@ export async function createUpdateTask( req, res ) {
83
83
  if ( data.upsertedId || req.body._id ) {
84
84
  checkListId = data?.upsertedId || req.body._id;
85
85
  let logInsertData = {
86
- action: req.body?._id ? 'checklistupdate' : 'checklistCreate',
86
+ action: req.body?._id ? 'taskUpdate' : 'taskCreate',
87
+ type: 'task',
87
88
  checklistId: checkListId,
88
89
  checkListName: inputBody.checklistName,
89
90
  createdBy: req.user._id,
90
91
  createdByName: req.user.userName,
91
92
  client_id: req.body.clientId,
92
93
  sections: inputBody?.sections,
94
+ createdByEmail: req.user.email,
93
95
  };
94
96
  await checklistLogs.create( logInsertData );
95
97
  let sectionList = [];
@@ -168,10 +170,16 @@ export async function createUpdateTask( req, res ) {
168
170
  }
169
171
  await taskQuestionService.insertMany( sectionList );
170
172
  let message = req.body?._id ? 'Task Updated Successfully' : 'Task Created Successfully';
173
+ if ( inputBody.submitType == 'save' ) {
174
+ message = 'Saved in draft successfully';
175
+ }
171
176
  return res.sendSuccess( { checklistId: checkListId, message: message } );
172
177
  } else {
173
178
  if ( inputBody.submitType == 'save' ) {
179
+ let message = 'Saved in draft successfully';
174
180
  return res.sendSuccess( { checklistId: checkListId, message: message } );
181
+ } else {
182
+ return res.sendSuccess( { message: 'Question is required' } );
175
183
  }
176
184
  }
177
185
  } else {
@@ -362,6 +370,13 @@ export async function validateUser( req, res ) {
362
370
  return res.sendSuccess( { validate: false, user: userEmail, store: storeId, domain: domainExists } );
363
371
  }
364
372
 
373
+ if ( req.body.hasOwnProperty( 'delete' ) ) {
374
+ let checkExists = await taskAssignService.findOne( { userEmail: req.body.assignedUsers[0].userEmail, storeName: req.body.assignedUsers[0].storeName, checkListId: req.body.id } );
375
+ if ( checkExists ) {
376
+ return res.sendError( 'User already exists', 400 );
377
+ }
378
+ }
379
+
365
380
  let id = await uploadUser( req, res );
366
381
  if ( id ) {
367
382
  return res.sendSuccess( { validate: true, id } );
@@ -429,9 +444,9 @@ export async function validateUser( req, res ) {
429
444
  }
430
445
  } else {
431
446
  if ( req.body.hasOwnProperty( 'delete' ) ) {
432
- let checkExists = await taskAssignService.findOne( { userEmail: req.body.assignedUsers[0].userEmail, storeName: req.body.assignedUsers[0].storeName } );
447
+ let checkExists = await taskAssignService.findOne( { userEmail: req.body.assignedUsers[0].userEmail, storeName: req.body.assignedUsers[0].storeName, checkListId: req.body.id } );
433
448
  if ( checkExists ) {
434
- return res.sendSuccess( 'User already exists' );
449
+ return res.sendError( 'User already exists', 400 );
435
450
  }
436
451
  }
437
452
 
@@ -652,11 +667,14 @@ export async function taskConfig( req, res ) {
652
667
 
653
668
  let logInsertData = {
654
669
  action: inputBody.submitType == 'publish' ? 'taskPublishUsingConfigPage' : 'taskConfigDraft',
670
+ type: 'task',
655
671
  checklistId: inputBody._id,
656
672
  checkListName: inputBody?.checkListName,
657
673
  createdBy: req.user._id,
658
674
  createdByName: req.user.userName,
659
675
  client_id: inputBody.client_id,
676
+ createdByEmail: req.user.email,
677
+ approver: inputBody?.approver || [],
660
678
  };
661
679
  await checklistLogs.create( logInsertData );
662
680
 
@@ -688,6 +706,7 @@ export async function taskConfig( req, res ) {
688
706
  checkListId: inputBody._id,
689
707
  type: 'task',
690
708
  client_id: inputBody.client_id,
709
+ checkListName: inputBody?.checkListName,
691
710
  } );
692
711
  }
693
712
  } );
@@ -751,12 +770,8 @@ export async function taskConfig( req, res ) {
751
770
  futureDaysDataRemove( currentDate, req.params.checklistId );
752
771
  }
753
772
  if ( response?.modifiedCount || response?.matchedCount || response?.upsertedCount ) {
754
- return res.sendSuccess( { id: inputBody._id, message: 'Configuration Updated Successfully' } );
755
- }
756
- if ( inputBody.submitType == 'save' ) {
757
- if ( response?.modifiedCount || response?.matchedCount || response?.upsertedCount ) {
758
- return res.sendSuccess( { message: 'Configuration Updated Successfully' } );
759
- }
773
+ let message = inputBody.submitType == 'publish' ? 'Configuration Updated Successfully' : 'Saved in draft successfully';
774
+ return res.sendSuccess( { id: inputBody._id, message: message } );
760
775
  }
761
776
  } catch ( e ) {
762
777
  logger.error( { functionName: 'taskConfig =>', error: e, message: req.body } );
@@ -806,6 +821,8 @@ export async function insertSingleProcessData( checklistId ) {
806
821
  insertdata.locationCount = getCLconfig.locationCount;
807
822
  insertdata.allowedMultiSubmit = false;
808
823
  insertdata.scheduleRepeatedType = 'daily';
824
+ insertdata.remainder = getCLconfig?.remainder || [];
825
+ insertdata.approver = getCLconfig?.approver || [];
809
826
  let collectSections = [];
810
827
  let sectionQuery = [];
811
828
  sectionQuery.push( {
@@ -827,21 +844,55 @@ export async function insertSingleProcessData( checklistId ) {
827
844
  }
828
845
  insertdata.questionAnswers = collectSections;
829
846
  insertdata.updatedAt = new Date();
830
- let insertdataquery = {};
831
- insertdataquery.date_string = insertdata.date_string;
832
- insertdataquery.date_iso = insertdata.date_iso;
833
- insertdataquery.client_id = insertdata.client_id;
834
- insertdataquery.sourceCheckList_id = insertdata.sourceCheckList_id;
835
- let updatedchecklist;
836
- let checklistDetails = await taskProcessedConfigService.findOne( insertdataquery );
837
- if ( !checklistDetails ) {
838
- updatedchecklist = await taskProcessedConfigService.insert( insertdata );
839
- } else {
840
- await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertdata );
841
- updatedchecklist = checklistDetails;
842
- }
843
- if ( updatedchecklist ) {
844
- insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedchecklist, date, startTimeIso, endTimeIso, insertdata );
847
+ function getDaysBeforeEndDate( endDate ) {
848
+ const end = dayjs.utc( endDate );
849
+ const now = dayjs.utc();
850
+
851
+ if ( end.isBefore( now ) ) {
852
+ throw new Error( 'End date must be in the future.' );
853
+ }
854
+
855
+ const daysArray = [];
856
+ let currentDate = now.startOf( 'day' );
857
+
858
+ while ( currentDate.isBefore( end ) ) {
859
+ daysArray.push( currentDate.format( ) );
860
+ currentDate = currentDate.add( 1, 'day' );
861
+ }
862
+
863
+ return daysArray;
864
+ };
865
+
866
+ const dateArray = getDaysBeforeEndDate( endDate );
867
+
868
+ for ( const dateVal of dateArray ) {
869
+ const insertdataquery = {
870
+ date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
871
+ date_iso: dayjs( dateVal ).toDate(),
872
+ client_id: insertdata.client_id,
873
+ sourceCheckList_id: insertdata.sourceCheckList_id,
874
+ };
875
+
876
+ const insertDataPerDay = {
877
+ ...insertdata,
878
+ date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
879
+ date_iso: dayjs( dateVal ).toDate(),
880
+ approver: getCLconfig?.approver,
881
+ };
882
+
883
+ let updatedchecklist;
884
+ let checklistDetails = await taskProcessedConfigService.findOne( insertdataquery );
885
+
886
+ if ( !checklistDetails ) {
887
+ updatedchecklist = await taskProcessedConfigService.insert( insertDataPerDay );
888
+ } else {
889
+ await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertDataPerDay );
890
+ updatedchecklist = checklistDetails;
891
+ }
892
+
893
+ if ( updatedchecklist ) {
894
+ await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata );
895
+ }
845
896
  }
846
897
  }
847
898
  }
@@ -852,14 +903,13 @@ export async function insertSingleProcessData( checklistId ) {
852
903
  }
853
904
  };
854
905
 
855
- async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
906
+ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
856
907
  let getquestionQuery = [];
857
908
  getquestionQuery.push( {
858
909
  $match: {
859
910
  checkListId: new ObjectId( checklistId ),
860
911
  checkFlag: true,
861
912
  isdeleted: false,
862
- // ...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
863
913
  },
864
914
  } );
865
915
  let allQuestion = await taskAssignService.aggregate( getquestionQuery );
@@ -893,7 +943,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
893
943
  element4.checkListName = getCLconfig.checkListName;
894
944
  element4.checkListDescription = getCLconfig.checkListDescription;
895
945
  element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
896
- element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
946
+ element4.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
897
947
  element4.allowedOverTime = false;
898
948
  element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
899
949
  element4.scheduleStartTime = '12:00 AM';
@@ -911,6 +961,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
911
961
  element4.scheduleRepeatedType = 'daily';
912
962
  element4.approvalEnable = getCLconfig.approver.length ? true : false;
913
963
  element4.priorityType = getCLconfig.priorityType;
964
+ element4.remainder = getCLconfig?.remainder || [];
914
965
  }
915
966
  if ( userIdList.length ) {
916
967
  allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
@@ -922,6 +973,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
922
973
  assigndeletequery.client_id = insertdata.client_id;
923
974
  assigndeletequery.checkListId = updatedchecklist._id;
924
975
  assigndeletequery.checklistStatus = { $nin: [ 'submit' ] };
976
+ assigndeletequery.redoStatus = false;
925
977
  await taskProcessedService.deleteMany( assigndeletequery );
926
978
  await taskProcessedService.insertMany( allQuestion );
927
979
  logger.info( { function: 'insertPCBulk_v3', query: assigndeletequery } );
@@ -1008,9 +1060,11 @@ export async function reinitiateTask( req, res ) {
1008
1060
  return res.sendError( 'no data found', 204 );
1009
1061
  }
1010
1062
  let data = {};
1063
+ let endDate = dayjs( req.body.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + req.body.scheduleEndTime;
1064
+ endDate = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
1011
1065
  data.scheduleDate = req.body.scheduleDate;
1012
1066
  data.scheduleEndTime = req.body.scheduleEndTime;
1013
- data.scheduleEndTimeISO = dayjs.utc( req.body.scheduleEndTime, 'hh:mm A' ).format();
1067
+ data.scheduleEndTimeISO = endDate;
1014
1068
  data.allowedStoreLocation = req.body.allowedStoreLocation;
1015
1069
  data.approver = req.body.approver;
1016
1070
  data.priorityType = req.body.priorityType;
@@ -1041,8 +1095,54 @@ export async function reinitiateTask( req, res ) {
1041
1095
  }
1042
1096
 
1043
1097
  await taskService.updateOne( { _id: req.body.taskId }, data );
1044
- await taskAssignService.updateOne( { userEmail: req.body.userEmail, storeName: req.body.storeName, checkListId: req.body.taskId }, { reinitiate: true } );
1045
- await insertSingleProcessData( req.body.taskId );
1098
+ function getDaysBeforeEndDate( endDate ) {
1099
+ const end = dayjs.utc( endDate );
1100
+ const now = dayjs.utc( req.body.previousEndDate ).add( 1, 'day' );
1101
+
1102
+ const daysArray = [];
1103
+ if ( !end.isBefore( now ) ) {
1104
+ let currentDate = now.startOf( 'day' );
1105
+
1106
+ while ( currentDate.isBefore( end ) ) {
1107
+ daysArray.push( currentDate.format( ) );
1108
+ currentDate = currentDate.add( 1, 'day' );
1109
+ }
1110
+ }
1111
+ return daysArray;
1112
+ };
1113
+
1114
+ const dateArray = getDaysBeforeEndDate( endDate );
1115
+ await taskProcessedService.updateMany( { userEmail: req.body.userEmail, store_id: req.body.store_id, date_iso: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) }, sourceCheckList_id: req.body.taskId }, { scheduleEndTime_iso: endDate } );
1116
+ await taskProcessedConfigService.updateMany( { date_iso: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) }, sourceCheckList_id: req.body.taskId }, { scheduleEndTime_iso: endDate } );
1117
+
1118
+ if ( dateArray.length ) {
1119
+ let getPreviousUserTaskDate = await taskProcessedService.findOne( { userEmail: req.body.userEmail, store_id: req.body.store_id, sourceCheckList_id: req.body.taskId } );
1120
+ if ( !getPreviousUserTaskDate ) {
1121
+ return res.sendError( 'No data found', 204 );
1122
+ }
1123
+ let getPreviousConfigDate = await taskProcessedConfigService.findOne( { sourceCheckList_id: req.body.taskId } );
1124
+
1125
+ for ( let date of dateArray ) {
1126
+ let configData = {
1127
+ ...getPreviousConfigDate._doc,
1128
+ date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
1129
+ date_iso: new Date( dayjs( date ).format( 'YYYY-MM-DD' ) ),
1130
+ };
1131
+
1132
+ let userTaskData = {
1133
+ ...getPreviousUserTaskDate._doc,
1134
+ date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
1135
+ date_iso: new Date( dayjs( date ).format( 'YYYY-MM-DD' ) ),
1136
+ };
1137
+
1138
+ delete configData._id;
1139
+ delete userTaskData._id;
1140
+
1141
+ await taskProcessedConfigService.insert( configData );
1142
+ await taskProcessedService.insert( userTaskData );
1143
+ }
1144
+ }
1145
+
1046
1146
  return res.sendSuccess( 'Task reinitaite SUccessfully' );
1047
1147
  } catch ( e ) {
1048
1148
  logger.error( { functionName: 'reinitiateTask', error: e } );
@@ -1124,7 +1224,9 @@ export async function createChecklistTask( req, res ) {
1124
1224
  inputBody.question[0].questionReferenceImage.forEach( ( ele ) => {
1125
1225
  let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
1126
1226
  let url = imgUrl.split( '/' );
1127
- url.splice( 0, 3 );
1227
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
1228
+ url.splice( 0, 3 );
1229
+ }
1128
1230
  images.push( url.join( '/' ) );
1129
1231
  } );
1130
1232
  inputBody.question[0].questionReferenceImage = images;
@@ -1134,7 +1236,7 @@ export async function createChecklistTask( req, res ) {
1134
1236
  inputBody.question[0].answers[0].referenceImage.forEach( ( ele ) => {
1135
1237
  let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
1136
1238
  let url = imgUrl.split( '/' );
1137
- if ( url.includes( 'https' ) || url.includes( 'http' ) ) {
1239
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
1138
1240
  url.splice( 0, 3 );
1139
1241
  }
1140
1242
  images.push( url.join( '/' ) );
@@ -1289,9 +1391,10 @@ export async function redoTask( req, res ) {
1289
1391
  if ( sectionIndex == -1 ) {
1290
1392
  return res.sendError( 'section is not found', 400 );
1291
1393
  }
1292
- let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
1394
+ let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
1293
1395
  let userAnswer = data.userAnswer;
1294
1396
  question[sectionIndex].questions[req.body.payload.qno - 1] = data;
1397
+ question[sectionIndex].questions[req.body.payload.qno - 1].remarks = '';
1295
1398
  question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
1296
1399
  taskDetails.questionAnswers = question;
1297
1400
  let updateData = {
@@ -1341,7 +1444,7 @@ export async function redoTask( req, res ) {
1341
1444
  return res.sendError( 'Something went wrong', 500 );
1342
1445
  }
1343
1446
  } catch ( e ) {
1344
- logger.error( { function: 'redoChecklist', error: e, message: req.body } );
1447
+ logger.error( { function: 'redoTask', error: e, message: req.body } );
1345
1448
  return res.sendError( e, 500 );
1346
1449
  }
1347
1450
  }
@@ -1512,12 +1615,23 @@ export async function approvalstatus( req, res ) {
1512
1615
  }
1513
1616
  let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
1514
1617
  if ( filterApprover.length === 0 ) {
1618
+ if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) ) {
1619
+ let url = JSON.parse( process.env.LAMBDAURL );
1620
+ let resultData = await LamdaServiceCall( url.approvalstatustask, req.body );
1621
+ if ( resultData ) {
1622
+ console.log( resultData.status_code );
1623
+ if ( resultData.status_code == '200' ) {
1624
+ return res.sendSuccess( resultData );
1625
+ }
1626
+ }
1627
+ return res.sendError( 'No Content', 204 );
1628
+ }
1515
1629
  return res.sendSuccess( 'suceess' );
1516
1630
  }
1517
1631
 
1518
1632
 
1519
1633
  let url = JSON.parse( process.env.LAMBDAURL );
1520
- let resultData = await LamdaServiceCall( url.approvalstatus, req.body );
1634
+ let resultData = await LamdaServiceCall( url.approvalstatustask, req.body );
1521
1635
  console.log( resultData );
1522
1636
  if ( resultData ) {
1523
1637
  if ( resultData.status_code == '200' ) {
@@ -1743,6 +1857,7 @@ export const updatePublish = async ( req, res ) => {
1743
1857
  createdBy: req.user._id,
1744
1858
  createdByName: req.user.userName,
1745
1859
  client_id: req.body.clientId,
1860
+ createdByEmail: req.user.email,
1746
1861
  };
1747
1862
  await checklistLogs.create( logInsertData );
1748
1863
  return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
@@ -1786,6 +1901,7 @@ export const duplicateChecklist = async ( req, res ) => {
1786
1901
  createdBy: req.user._id,
1787
1902
  createdByName: req.user.userName,
1788
1903
  client_id: req.query.clientId,
1904
+ createdByEmail: req.user.email,
1789
1905
  };
1790
1906
  await checklistLogs.create( logInsertData );
1791
1907
  taskService.create( dupDetails ).then( async ( data ) => {
@@ -107,11 +107,16 @@ export const taskTableV1 = async ( req, res ) => {
107
107
  let offset = parseInt( req.body.offset - 1 ) || 0;
108
108
  let page = offset * limit;
109
109
  let query = [];
110
+ let fromDate = new Date( req.body.fromDate );
111
+ let toDate = new Date( req.body.toDate );
112
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
113
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
114
+ toDate.setUTCHours( 23, 59, 59, 59 );
110
115
 
111
116
  query.push(
112
117
  {
113
118
  $match: {
114
- // checkListType: 'task',
119
+ date_iso: { $gte: fromDate, $lte: toDate },
115
120
  client_id: req.body.clientId,
116
121
  isdeleted: false,
117
122
  },
@@ -218,21 +223,15 @@ export const taskTableV1 = async ( req, res ) => {
218
223
  export const taskInfoTableV1 = async ( req, res ) => {
219
224
  try {
220
225
  let requestData = req.body;
221
- // let fromDate = new Date( requestData.fromDate );
222
- // let toDate = new Date( requestData.toDate );
223
- // let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
224
- // toDate = new Date( toDate.getTime() - userTimezoneOffset );
225
- // toDate.setUTCHours( 23, 59, 59, 59 );
226
226
  let result = {};
227
227
 
228
228
  let findQuery = [];
229
229
  let findAndQuery = [];
230
230
 
231
231
  findAndQuery.push(
232
- // { date_iso: { $gte: fromDate, $lte: toDate } },
232
+ { date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
233
233
  { client_id: requestData.clientId },
234
234
  { store_id: { $in: requestData.storeId } },
235
- // { checkListType: { $eq: 'task' } },
236
235
  { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
237
236
  );
238
237
  if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
@@ -259,8 +258,37 @@ export const taskInfoTableV1 = async ( req, res ) => {
259
258
  findQuery.push( { $match: { $or: [ query ] } } );
260
259
  }
261
260
 
261
+ findQuery.push( { $sort: { date_iso: -1, userName: 1 } } );
262
+
263
+ findQuery.push(
264
+ {
265
+ $group: {
266
+ _id: { userEmail: '$userEmail', storeId: '$store_id', checklistStatus: '$checklistStatus' },
267
+ checkListName: { $first: '$checkListName' },
268
+ createdByName: { $first: '$createdByName' },
269
+ userName: { $first: '$userName' },
270
+ userEmail: { $first: '$userEmail' },
271
+ checklistStatus: { $first: '$checklistStatus' },
272
+ submitTime_string: { $first: '$submitTime_string' },
273
+ storeName: { $first: '$storeName' },
274
+ checkListType: { $first: '$checkListType' },
275
+ scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
276
+ date_iso: { $first: '$date_iso' },
277
+ store_id: { $first: '$store_id' },
278
+ timeFlag: { $first: '$timeFlag' },
279
+ date_string: { $first: '$date_string' },
280
+ sourceCheckList_id: { $first: '$sourceCheckList_id' },
281
+ reinitiateStatus: { $first: '$reinitiateStatus' },
282
+ scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
283
+ processedchecklistId: { $first: '$_id' },
284
+ redoStatus: { $first: '$redoStatus' },
285
+ },
286
+ },
287
+ );
288
+
262
289
  findQuery.push( {
263
290
  $project: {
291
+ _id: 0,
264
292
  checkListName: 1,
265
293
  createdByName: 1,
266
294
  userName: 1,
@@ -277,12 +305,14 @@ export const taskInfoTableV1 = async ( req, res ) => {
277
305
  sourceCheckList_id: 1,
278
306
  reinitiateStatus: 1,
279
307
  scheduleEndTime_iso: 1,
280
-
308
+ processedchecklistId: 1,
309
+ redoStatus: 1,
281
310
  },
282
311
  } );
283
312
 
284
313
  findQuery.push( {
285
314
  $project: {
315
+ _id: 0,
286
316
  checkListName: 1,
287
317
  checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
288
318
  createdByName: 1,
@@ -316,13 +346,15 @@ export const taskInfoTableV1 = async ( req, res ) => {
316
346
  checklistDate: '$date_string',
317
347
  sourceCheckList_id: 1,
318
348
  scheduleEndTime_iso: 1,
349
+ processedchecklistId: 1,
350
+ redoStatus: 1,
319
351
  },
320
352
  } );
321
353
 
322
354
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
323
355
  findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
324
356
  } else {
325
- findQuery.push( { $sort: { ['date_iso']: -1 } } );
357
+ findQuery.push( { $sort: { userEmail: 1 } } );
326
358
  }
327
359
 
328
360
  let limit = parseInt( requestData?.limit ) || 10;
@@ -348,7 +380,8 @@ export const taskInfoTableV1 = async ( req, res ) => {
348
380
 
349
381
  result.totalCount = taskInfoData[0].count[0].total;
350
382
  for ( let i = 0; i < taskInfoData[0].data.length; i++ ) {
351
- taskInfoData[0].data[i].scheduleEndTime_iso = dayjs( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
383
+ taskInfoData[0].data[i].date = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format();
384
+ taskInfoData[0].data[i].scheduleEndTime_iso = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
352
385
  }
353
386
  result.taskInfo = taskInfoData[0].data;
354
387
  return res.sendSuccess( result );
@@ -689,13 +722,13 @@ export const taskDropdownListV1 = async ( req, res ) => {
689
722
  findQuery.push(
690
723
  {
691
724
  $group: {
692
- _id: '$sourceCheckList_id',
725
+ _id: '$_id',
693
726
  checkListName: { $first: '$checkListName' },
694
727
  checkListType: { $first: '$checkListType' },
695
728
  createdByName: { $first: '$createdByName' },
696
729
  storeCount: { $first: '$storeCount' },
697
- scheduleEndTimeISO: { $first: '$scheduleEndTime_iso' },
698
- submitTime_string: { $first: '$submitTime_string' },
730
+ scheduleEndTimeISO: { $first: '$scheduleEndTimeISO' },
731
+ // submitTime_string: { $first: '$submitTime_string' },
699
732
  },
700
733
  },
701
734
  );
@@ -709,7 +742,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
709
742
  createdByName: 1,
710
743
  storeCount: 1,
711
744
  scheduleEndTimeISO: 1,
712
- submitTime_string: 1,
745
+ // submitTime_string: 1,
713
746
  },
714
747
  } );
715
748
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
@@ -717,7 +750,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
717
750
  } else {
718
751
  findQuery.push( { $sort: { ['checkListNameLowercase']: 1 } } );
719
752
  }
720
- let getChecklistData = await processedTaskService.aggregate( findQuery );
753
+ let getChecklistData = await taskService.aggregate( findQuery );
721
754
  if ( !getChecklistData.length ) {
722
755
  return res.sendError( { error: 'No Data Found' }, 204 );
723
756
  }
@@ -13,7 +13,7 @@ taskRouter
13
13
  .post( '/upload', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.validateUser )
14
14
  .post( '/uploadImage', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.uploadImage )
15
15
  .post( '/config', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.taskConfig )
16
- .post( '/reinitiate', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
16
+ .post( '/reinitiate', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
17
17
  .post( '/checklistTask', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.createChecklistTask )
18
18
  .post( '/updateApprove', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.approveTask )
19
19
  .post( '/redo', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.redoTask )
@@ -5,7 +5,7 @@ export const find = async ( query = {}, field={} ) => {
5
5
  };
6
6
 
7
7
  export const findOne = async ( query = {}, field={} ) => {
8
- return model.taskProcessedConfigModel.findOne( query, field );
8
+ return model.taskProcessedConfigModel.findOne( query, field ).sort( { date_iso: -1 } );
9
9
  };
10
10
 
11
11
  export const updateMany = async ( query = {}, record={} ) => {
@@ -5,7 +5,7 @@ export const find = async ( query = {}, field={} ) => {
5
5
  };
6
6
 
7
7
  export const findOne = async ( query = {}, field={} ) => {
8
- return model.taskProcessedModel.findOne( query, field );
8
+ return model.taskProcessedModel.findOne( query, field ).sort( { date_iso: -1 } );
9
9
  };
10
10
 
11
11
  export const updateMany = async ( query = {}, record={} ) => {
@@ -28,3 +28,7 @@ export const aggregate = async ( query = [] ) => {
28
28
  return model.taskProcessedModel.aggregate( query );
29
29
  };
30
30
 
31
+ export const insert = async ( query = [] ) => {
32
+ return model.taskProcessedModel.create( query );
33
+ };
34
+