tango-app-api-task 1.0.0-beta.2 → 1.0.0-beta.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-task",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
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.1.99",
28
- "tango-app-api-middleware": "^3.1.43-alpha.10",
27
+ "tango-api-schema": "^2.2.3",
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 = [];
@@ -652,11 +654,14 @@ export async function taskConfig( req, res ) {
652
654
 
653
655
  let logInsertData = {
654
656
  action: inputBody.submitType == 'publish' ? 'taskPublishUsingConfigPage' : 'taskConfigDraft',
657
+ type: 'task',
655
658
  checklistId: inputBody._id,
656
659
  checkListName: inputBody?.checkListName,
657
660
  createdBy: req.user._id,
658
661
  createdByName: req.user.userName,
659
662
  client_id: inputBody.client_id,
663
+ createdByEmail: req.user.email,
664
+ approver: inputBody?.approver || [],
660
665
  };
661
666
  await checklistLogs.create( logInsertData );
662
667
 
@@ -688,6 +693,7 @@ export async function taskConfig( req, res ) {
688
693
  checkListId: inputBody._id,
689
694
  type: 'task',
690
695
  client_id: inputBody.client_id,
696
+ checkListName: inputBody?.checkListName,
691
697
  } );
692
698
  }
693
699
  } );
@@ -827,21 +833,55 @@ export async function insertSingleProcessData( checklistId ) {
827
833
  }
828
834
  insertdata.questionAnswers = collectSections;
829
835
  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 );
836
+ function getDaysBeforeEndDate( endDate ) {
837
+ const end = dayjs.utc( endDate );
838
+ const now = dayjs.utc();
839
+
840
+ if ( end.isBefore( now ) ) {
841
+ throw new Error( 'End date must be in the future.' );
842
+ }
843
+
844
+ const daysArray = [];
845
+ let currentDate = now.startOf( 'day' );
846
+
847
+ while ( currentDate.isBefore( end ) ) {
848
+ daysArray.push( currentDate.format( ) );
849
+ currentDate = currentDate.add( 1, 'day' );
850
+ }
851
+
852
+ return daysArray;
853
+ };
854
+
855
+ const dateArray = getDaysBeforeEndDate( endDate );
856
+
857
+ for ( const dateVal of dateArray ) {
858
+ const insertdataquery = {
859
+ date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
860
+ date_iso: dayjs( dateVal ).toDate(),
861
+ client_id: insertdata.client_id,
862
+ sourceCheckList_id: insertdata.sourceCheckList_id,
863
+ };
864
+
865
+ const insertDataPerDay = {
866
+ ...insertdata,
867
+ date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
868
+ date_iso: dayjs( dateVal ).toDate(),
869
+ approver: getCLconfig?.approver,
870
+ };
871
+
872
+ let updatedchecklist;
873
+ let checklistDetails = await taskProcessedConfigService.findOne( insertdataquery );
874
+
875
+ if ( !checklistDetails ) {
876
+ updatedchecklist = await taskProcessedConfigService.insert( insertDataPerDay );
877
+ } else {
878
+ await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertDataPerDay );
879
+ updatedchecklist = checklistDetails;
880
+ }
881
+
882
+ if ( updatedchecklist ) {
883
+ await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata );
884
+ }
845
885
  }
846
886
  }
847
887
  }
@@ -852,14 +892,13 @@ export async function insertSingleProcessData( checklistId ) {
852
892
  }
853
893
  };
854
894
 
855
- async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
895
+ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
856
896
  let getquestionQuery = [];
857
897
  getquestionQuery.push( {
858
898
  $match: {
859
899
  checkListId: new ObjectId( checklistId ),
860
900
  checkFlag: true,
861
901
  isdeleted: false,
862
- // ...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
863
902
  },
864
903
  } );
865
904
  let allQuestion = await taskAssignService.aggregate( getquestionQuery );
@@ -893,7 +932,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
893
932
  element4.checkListName = getCLconfig.checkListName;
894
933
  element4.checkListDescription = getCLconfig.checkListDescription;
895
934
  element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
896
- element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
935
+ element4.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
897
936
  element4.allowedOverTime = false;
898
937
  element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
899
938
  element4.scheduleStartTime = '12:00 AM';
@@ -1008,9 +1047,11 @@ export async function reinitiateTask( req, res ) {
1008
1047
  return res.sendError( 'no data found', 204 );
1009
1048
  }
1010
1049
  let data = {};
1050
+ let endDate = dayjs( req.body.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + req.body.scheduleEndTime;
1051
+ endDate = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
1011
1052
  data.scheduleDate = req.body.scheduleDate;
1012
1053
  data.scheduleEndTime = req.body.scheduleEndTime;
1013
- data.scheduleEndTimeISO = dayjs.utc( req.body.scheduleEndTime, 'hh:mm A' ).format();
1054
+ data.scheduleEndTimeISO = endDate;
1014
1055
  data.allowedStoreLocation = req.body.allowedStoreLocation;
1015
1056
  data.approver = req.body.approver;
1016
1057
  data.priorityType = req.body.priorityType;
@@ -1041,8 +1082,55 @@ export async function reinitiateTask( req, res ) {
1041
1082
  }
1042
1083
 
1043
1084
  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 );
1085
+ function getDaysBeforeEndDate( endDate ) {
1086
+ const end = dayjs.utc( endDate );
1087
+ const now = dayjs.utc( req.body.previousEndDate ).add( 1, 'day' );
1088
+
1089
+ if ( end.isBefore( now ) ) {
1090
+ throw new Error( 'End date must be in the future.' );
1091
+ }
1092
+
1093
+ const daysArray = [];
1094
+ let currentDate = now.startOf( 'day' );
1095
+
1096
+ while ( currentDate.isBefore( end ) ) {
1097
+ daysArray.push( currentDate.format( ) );
1098
+ currentDate = currentDate.add( 1, 'day' );
1099
+ }
1100
+
1101
+ return daysArray;
1102
+ };
1103
+
1104
+ const dateArray = getDaysBeforeEndDate( endDate );
1105
+ console.log( dateArray );
1106
+ 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 } );
1107
+ await taskProcessedConfigService.updateMany( { date_iso: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) }, sourceCheckList_id: req.body.taskId }, { scheduleEndTime_iso: endDate } );
1108
+
1109
+ let getPreviousUserTaskDate = await taskProcessedService.findOne( { userEmail: req.body.userEmail, store_id: req.body.store_id, sourceCheckList_id: req.body.taskId } );
1110
+ if ( !getPreviousUserTaskDate ) {
1111
+ return res.sendError( 'No data found', 204 );
1112
+ }
1113
+ let getPreviousConfigDate = await taskProcessedConfigService.findOne( { sourceCheckList_id: req.body.taskId } );
1114
+
1115
+ for ( let date of dateArray ) {
1116
+ let configData = {
1117
+ ...getPreviousConfigDate._doc,
1118
+ date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
1119
+ date_iso: new Date( dayjs( date ).format( 'YYYY-MM-DD' ) ),
1120
+ };
1121
+
1122
+ let userTaskData = {
1123
+ ...getPreviousUserTaskDate._doc,
1124
+ date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
1125
+ date_iso: new Date( dayjs( date ).format( 'YYYY-MM-DD' ) ),
1126
+ };
1127
+
1128
+ delete configData._id;
1129
+ delete userTaskData._id;
1130
+
1131
+ await taskProcessedConfigService.insert( configData );
1132
+ await taskProcessedService.insert( userTaskData );
1133
+ }
1046
1134
  return res.sendSuccess( 'Task reinitaite SUccessfully' );
1047
1135
  } catch ( e ) {
1048
1136
  logger.error( { functionName: 'reinitiateTask', error: e } );
@@ -1124,7 +1212,9 @@ export async function createChecklistTask( req, res ) {
1124
1212
  inputBody.question[0].questionReferenceImage.forEach( ( ele ) => {
1125
1213
  let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
1126
1214
  let url = imgUrl.split( '/' );
1127
- url.splice( 0, 3 );
1215
+ if ( url.includes( 'https' ) || url.includes( 'http' ) ) {
1216
+ url.splice( 0, 3 );
1217
+ }
1128
1218
  images.push( url.join( '/' ) );
1129
1219
  } );
1130
1220
  inputBody.question[0].questionReferenceImage = images;
@@ -1289,7 +1379,7 @@ export async function redoTask( req, res ) {
1289
1379
  if ( sectionIndex == -1 ) {
1290
1380
  return res.sendError( 'section is not found', 400 );
1291
1381
  }
1292
- let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
1382
+ let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
1293
1383
  let userAnswer = data.userAnswer;
1294
1384
  question[sectionIndex].questions[req.body.payload.qno - 1] = data;
1295
1385
  question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
@@ -1743,6 +1833,7 @@ export const updatePublish = async ( req, res ) => {
1743
1833
  createdBy: req.user._id,
1744
1834
  createdByName: req.user.userName,
1745
1835
  client_id: req.body.clientId,
1836
+ createdByEmail: req.user.email,
1746
1837
  };
1747
1838
  await checklistLogs.create( logInsertData );
1748
1839
  return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
@@ -1786,6 +1877,7 @@ export const duplicateChecklist = async ( req, res ) => {
1786
1877
  createdBy: req.user._id,
1787
1878
  createdByName: req.user.userName,
1788
1879
  client_id: req.query.clientId,
1880
+ createdByEmail: req.user.email,
1789
1881
  };
1790
1882
  await checklistLogs.create( logInsertData );
1791
1883
  taskService.create( dupDetails ).then( async ( data ) => {
@@ -218,21 +218,15 @@ export const taskTableV1 = async ( req, res ) => {
218
218
  export const taskInfoTableV1 = async ( req, res ) => {
219
219
  try {
220
220
  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
221
  let result = {};
227
222
 
228
223
  let findQuery = [];
229
224
  let findAndQuery = [];
230
225
 
231
226
  findAndQuery.push(
232
- // { date_iso: { $gte: fromDate, $lte: toDate } },
227
+ { date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
233
228
  { client_id: requestData.clientId },
234
229
  { store_id: { $in: requestData.storeId } },
235
- // { checkListType: { $eq: 'task' } },
236
230
  { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
237
231
  );
238
232
  if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
@@ -259,8 +253,36 @@ export const taskInfoTableV1 = async ( req, res ) => {
259
253
  findQuery.push( { $match: { $or: [ query ] } } );
260
254
  }
261
255
 
256
+ findQuery.push( { $sort: { date_iso: -1, userName: 1 } } );
257
+
258
+ findQuery.push(
259
+ {
260
+ $group: {
261
+ _id: { userEmail: '$userEmail', storeId: '$store_id' },
262
+ checkListName: { $first: '$checkListName' },
263
+ createdByName: { $first: '$createdByName' },
264
+ userName: { $first: '$userName' },
265
+ userEmail: { $first: '$userEmail' },
266
+ checklistStatus: { $first: '$checklistStatus' },
267
+ submitTime_string: { $first: '$submitTime_string' },
268
+ storeName: { $first: '$storeName' },
269
+ checkListType: { $first: '$checkListType' },
270
+ scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
271
+ date_iso: { $first: '$date_iso' },
272
+ store_id: { $first: '$store_id' },
273
+ timeFlag: { $first: '$timeFlag' },
274
+ date_string: { $first: '$date_string' },
275
+ sourceCheckList_id: { $first: '$sourceCheckList_id' },
276
+ reinitiateStatus: { $first: '$reinitiateStatus' },
277
+ scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
278
+ processedchecklistId: { $first: '$_id' },
279
+ },
280
+ },
281
+ );
282
+
262
283
  findQuery.push( {
263
284
  $project: {
285
+ _id: 0,
264
286
  checkListName: 1,
265
287
  createdByName: 1,
266
288
  userName: 1,
@@ -277,12 +299,13 @@ export const taskInfoTableV1 = async ( req, res ) => {
277
299
  sourceCheckList_id: 1,
278
300
  reinitiateStatus: 1,
279
301
  scheduleEndTime_iso: 1,
280
-
302
+ processedchecklistId: 1,
281
303
  },
282
304
  } );
283
305
 
284
306
  findQuery.push( {
285
307
  $project: {
308
+ _id: 0,
286
309
  checkListName: 1,
287
310
  checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
288
311
  createdByName: 1,
@@ -316,13 +339,14 @@ export const taskInfoTableV1 = async ( req, res ) => {
316
339
  checklistDate: '$date_string',
317
340
  sourceCheckList_id: 1,
318
341
  scheduleEndTime_iso: 1,
342
+ processedchecklistId: 1,
319
343
  },
320
344
  } );
321
345
 
322
346
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
323
347
  findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
324
348
  } else {
325
- findQuery.push( { $sort: { ['date_iso']: -1 } } );
349
+ findQuery.push( { $sort: { userEmail: 1 } } );
326
350
  }
327
351
 
328
352
  let limit = parseInt( requestData?.limit ) || 10;
@@ -348,7 +372,8 @@ export const taskInfoTableV1 = async ( req, res ) => {
348
372
 
349
373
  result.totalCount = taskInfoData[0].count[0].total;
350
374
  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' );
375
+ taskInfoData[0].data[i].date = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format();
376
+ taskInfoData[0].data[i].scheduleEndTime_iso = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
352
377
  }
353
378
  result.taskInfo = taskInfoData[0].data;
354
379
  return res.sendSuccess( result );
@@ -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
+