tango-app-api-trax 1.0.0-task.124 → 1.0.0-task.126

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": "1.0.0-task.124",
3
+ "version": "1.0.0-task.126",
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.1.91",
29
+ "tango-api-schema": "^2.1.94",
30
30
  "tango-app-api-middleware": "^3.1.43-alpha.10",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -961,7 +961,7 @@ export async function pushNotification( req, res ) {
961
961
  return res.sendError( 'no data found', 204 );
962
962
  }
963
963
 
964
- checklistDetails.forEach( async ( item ) => {
964
+ for ( let [ index, item ] of checklistDetails.entries() ) {
965
965
  const message = {
966
966
  tokens: item.token,
967
967
  notification: {
@@ -974,10 +974,14 @@ export async function pushNotification( req, res ) {
974
974
  };
975
975
  const response = await admin.messaging().sendEachForMulticast( message );
976
976
  if ( response.successCount ) {
977
- return res.sendSuccess( 'Push notification send successfully' );
977
+ logger.info( { message: 'push notification', success: item.token } );
978
+ if ( index == checklistDetails.length - 1 ) {
979
+ return res.sendSuccess( 'Push notification send successfully' );
980
+ }
981
+ } else {
982
+ logger.error( { message: 'push notification', error: item.token } );
978
983
  }
979
- return res.sendError( 'Push notification send Failed', 500 );
980
- } );
984
+ }
981
985
  } catch ( e ) {
982
986
  logger.error( { function: 'pushNotification', error: e } );
983
987
  return res.sendError( e, 500 );
@@ -108,136 +108,138 @@ export async function startChecklist( req, res ) {
108
108
 
109
109
  if ( getBeforeChecklist[0].checklistStatus != 'open' ) {
110
110
  return res.sendError( 'already check list started', 400 );
111
- } else {
112
- logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
113
- let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
114
- let updateQuery = {};
115
- updateQuery._id = new ObjectId( requestData.processedcheckListId );
116
- updateQuery.userId = req.user._id;
117
- updateQuery.date_string = requestData.date;
111
+ }
118
112
 
119
- if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
120
- await PCLQusestion.questionAnswers.forEach( ( section ) => {
121
- section.questions.forEach( ( question ) => {
122
- if ( question.answerType == 'multiplechoicemultiple' ) {
123
- let Multianswer = [];
124
- if ( question.answers.length > 0 ) {
125
- question.answers.forEach( ( answer, ansIndex ) => {
126
- Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
127
- answer.index = ansIndex;
128
- } );
129
- question.Multianswer = Multianswer;
130
- }
131
- } else if ( question.answerType == 'multipleImage' ) {
132
- let Multianswer = [];
133
- if ( question.answers.length > 0 ) {
134
- question.answers.forEach( ( answer, ansIndex ) => {
135
- Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
136
- answer.index = ansIndex;
137
- } );
138
- question.Multianswer = Multianswer;
139
- }
140
- } else {
141
- question.Multianswer = [];
113
+ logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
114
+ let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
115
+ let updateQuery = {};
116
+ updateQuery._id = new ObjectId( requestData.processedcheckListId );
117
+ updateQuery.userId = req.user._id;
118
+ updateQuery.date_string = requestData.date;
119
+
120
+ if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
121
+ await PCLQusestion.questionAnswers.forEach( ( section ) => {
122
+ section.questions.forEach( ( question ) => {
123
+ if ( question.answerType == 'multiplechoicemultiple' ) {
124
+ let Multianswer = [];
125
+ if ( question.answers.length > 0 ) {
126
+ question.answers.forEach( ( answer, ansIndex ) => {
127
+ Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
128
+ answer.index = ansIndex;
129
+ } );
130
+ question.Multianswer = Multianswer;
142
131
  }
143
- } );
132
+ } else if ( question.answerType == 'multipleImage' ) {
133
+ let Multianswer = [];
134
+ if ( question.answers.length > 0 ) {
135
+ question.answers.forEach( ( answer, ansIndex ) => {
136
+ Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
137
+ answer.index = ansIndex;
138
+ } );
139
+ question.Multianswer = Multianswer;
140
+ }
141
+ } else {
142
+ question.Multianswer = [];
143
+ }
144
144
  } );
145
- }
146
-
147
- let updateData = {};
148
- let storeTimeZone = await storeService.findOne( { storeName: getBeforeChecklist[0].storeName }, { 'storeProfile.timeZone': 1 } );
149
- let currentDateTime;
150
- if ( storeTimeZone?.storeProfile?.timeZone ) {
151
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
152
- } else {
153
- currentDateTime = dayjs();
154
- }
155
- updateData.checklistStatus = 'inprogress';
156
- updateData.startMobileTime = requestData?.currentTime;
157
- updateData.questionAnswers = getBeforeChecklist.redoStatus ? getBeforeChecklist.questionAnswers : PCLQusestion.questionAnswers;
158
- // const newDateTime = currentDateTime.add(5, 'hours').add(30, 'minutes');
159
- // updateData.startTime_string = newDateTime.format('hh:mm A, DD MMM');
160
- updateData.startTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
161
- updateData.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
145
+ } );
146
+ }
162
147
 
163
- let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
164
- PCLQusestion.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
165
- PCLQusestion.save();
166
- if ( updatechecklist ) {
167
- findQuery.push( {
168
- $project: {
169
- checkListName: { $ifNull: [ '$checkListName', '' ] },
170
- scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
171
- scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
172
- scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
173
- scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
174
- checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
175
- checkListId: { $ifNull: [ '$checkListId', '' ] },
176
- startTime: { $ifNull: [ '$startTime', '' ] },
177
- submitTime: { $ifNull: [ '$submitTime', '' ] },
178
- allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
179
- allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
180
- questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
181
- },
182
- } );
183
- let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
184
- let bucket = JSON.parse( process.env.BUCKET );
185
- getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
186
- section.questions.forEach( async ( question ) => {
187
- if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
188
- question.questionReferenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( question.questionReferenceImage ) } );
148
+ let updateData = {};
149
+ let storeTimeZone = await storeService.findOne( { storeName: getBeforeChecklist[0].storeName }, { 'storeProfile.timeZone': 1 } );
150
+ let currentDateTime;
151
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
152
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
153
+ } else {
154
+ currentDateTime = dayjs();
155
+ }
156
+ updateData.checklistStatus = 'inprogress';
157
+ updateData.startMobileTime = requestData?.currentTime;
158
+ updateData.questionAnswers = getBeforeChecklist[0]?.redoStatus ? getBeforeChecklist[0].questionAnswers : PCLQusestion.questionAnswers;
159
+ // const newDateTime = currentDateTime.add(5, 'hours').add(30, 'minutes');
160
+ // updateData.startTime_string = newDateTime.format('hh:mm A, DD MMM');
161
+ updateData.startTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
162
+ updateData.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
163
+
164
+ let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
165
+ PCLQusestion.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
166
+ PCLQusestion.save();
167
+ if ( updatechecklist.modifiedCount > 0 ) {
168
+ findQuery.push( {
169
+ $project: {
170
+ checkListName: { $ifNull: [ '$checkListName', '' ] },
171
+ scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
172
+ scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
173
+ scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
174
+ scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
175
+ checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
176
+ checkListId: { $ifNull: [ '$checkListId', '' ] },
177
+ startTime: { $ifNull: [ '$startTime', '' ] },
178
+ submitTime: { $ifNull: [ '$submitTime', '' ] },
179
+ allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
180
+ allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
181
+ questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
182
+ redoStatus: { $ifNull: [ '$redoStatus', '' ] },
183
+ },
184
+ } );
185
+ let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
186
+ let bucket = JSON.parse( process.env.BUCKET );
187
+ getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
188
+ section.questions.forEach( async ( question ) => {
189
+ if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
190
+ question.questionReferenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( question.questionReferenceImage ) } );
191
+ }
192
+ question.answers.forEach( async ( answer ) => {
193
+ if ( answer.referenceImage != '' ) {
194
+ answer.referenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( answer.referenceImage ) } );
189
195
  }
190
- question.answers.forEach( async ( answer ) => {
191
- if ( answer.referenceImage != '' ) {
192
- answer.referenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( answer.referenceImage ) } );
193
- }
194
- } );
195
196
  } );
196
197
  } );
197
- let logInsertData = {
198
- store_id: getBeforeChecklist[0].store_id,
199
- storeName: getBeforeChecklist[0].storeName,
200
- action: 'started',
201
- checklistId: getBeforeChecklist[0].checkListId,
202
- checkListName: getBeforeChecklist[0].checkListName,
203
- client_id: req.user.clientId,
204
- };
205
- await checklistLogs.create( logInsertData );
198
+ } );
199
+ let logInsertData = {
200
+ store_id: getBeforeChecklist[0].store_id,
201
+ storeName: getBeforeChecklist[0].storeName,
202
+ action: 'started',
203
+ checklistId: getBeforeChecklist[0].checkListId,
204
+ checkListName: getBeforeChecklist[0].checkListName,
205
+ checkListType: getBeforeChecklist[0].checkListType,
206
+ client_id: req.user.clientId,
207
+ };
208
+ await checklistLogs.create( logInsertData );
206
209
 
207
- let getchecklist = getupdatedchecklist;
208
- let questions = [];
209
- function processQuestion( question, section, questions, nested=false ) {
210
- let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
211
- if ( findExists && nested ) {
212
- let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
213
- questions.splice( findIndex, 1 );
214
- questions.push( question );
215
- }
216
- if ( !findExists ) {
217
- questions.push( question );
218
- for ( let answer of question.answers ) {
219
- if ( answer.showLinked && answer?.linkedQuestion != '' ) {
220
- let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
221
- if ( linkedQuestion ) {
222
- processQuestion( linkedQuestion, section, questions, true );
223
- }
210
+ let getchecklist = getupdatedchecklist;
211
+ let questions = [];
212
+ function processQuestion( question, section, questions, nested=false ) {
213
+ let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
214
+ if ( findExists && nested ) {
215
+ let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
216
+ questions.splice( findIndex, 1 );
217
+ questions.push( question );
218
+ }
219
+ if ( !findExists ) {
220
+ questions.push( question );
221
+ for ( let answer of question.answers ) {
222
+ if ( answer.showLinked && answer?.linkedQuestion != '' ) {
223
+ let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
224
+ if ( linkedQuestion ) {
225
+ processQuestion( linkedQuestion, section, questions, true );
224
226
  }
225
227
  }
226
228
  }
227
229
  }
228
- for ( let [ index, data ] of getchecklist.entries() ) {
229
- for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
230
- questions = [];
231
- for ( let question of section.questions ) {
232
- processQuestion( question, section, questions );
233
- }
234
- getchecklist[index].questionAnswers[secIndex].questions = questions;
230
+ }
231
+ for ( let [ index, data ] of getchecklist.entries() ) {
232
+ for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
233
+ questions = [];
234
+ for ( let question of section.questions ) {
235
+ processQuestion( question, section, questions );
235
236
  }
237
+ getchecklist[index].questionAnswers[secIndex].questions = questions;
236
238
  }
237
- return res.sendSuccess( getchecklist );
238
- } else {
239
- return res.sendError( 'something went wrong please try again', 500 );
240
239
  }
240
+ return res.sendSuccess( getchecklist );
241
+ } else {
242
+ return res.sendError( 'something went wrong please try again', 500 );
241
243
  }
242
244
  } catch ( e ) {
243
245
  logger.error( { function: 'startChecklist', error: e } );
@@ -319,7 +321,7 @@ export async function startTask( req, res ) {
319
321
 
320
322
  const updateTaskResult = await processedTask.updateOne( updateQuery, updateData );
321
323
 
322
- if ( !updateTaskResult ) {
324
+ if ( !updateTaskResult?.matchedCount ) {
323
325
  return res.sendError( 'Something went wrong, please try again', 500 );
324
326
  }
325
327
 
@@ -340,6 +342,7 @@ export async function startTask( req, res ) {
340
342
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
341
343
  allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', false ] },
342
344
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
345
+ redoStatus: { $ifNull: [ '$redoStatus', '' ] },
343
346
  },
344
347
  } );
345
348
  const getUpdatedTask = await processedTask.aggregate( findQuery );
@@ -376,6 +379,7 @@ export async function startTask( req, res ) {
376
379
  action: 'started',
377
380
  checklistId: task.checkListId,
378
381
  checkListName: task.checkListName,
382
+ checkListType: task.checkListType,
379
383
  client_id: user.clientId,
380
384
  };
381
385
  await checklistLogs.create( logData );
@@ -574,12 +578,14 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
574
578
  structure.remarks = requestSection[i].remarks;
575
579
  structure.answers = qaAnswers[j].answers;
576
580
  structure.userAnswer = yn;
577
- structure.linkType = qaAnswers[j].linkType,
578
- structure.linkquestionenabled = requestSection[i].linkquestionenabled,
579
- structure.parentanswer = requestSection[i].parentanswer,
580
- structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
581
- structure.descriptivetype = qaAnswers[j].descriptivetype,
582
- structure.redo = qaAnswers[j]?.redo,
581
+ structure.linkType = qaAnswers[j].linkType;
582
+ structure.linkquestionenabled = requestSection[i].linkquestionenabled;
583
+ structure.parentanswer = requestSection[i].parentanswer;
584
+ structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
585
+ structure.descriptivetype = qaAnswers[j].descriptivetype;
586
+ if ( qaAnswers[j]?.redo ) {
587
+ structure.redo = false;
588
+ }
583
589
  newArray.push( structure );
584
590
  } else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
585
591
  let qaans = qaAnswers[j].answers;
@@ -614,12 +620,14 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
614
620
  structure.remarks = requestSection[i].remarks;
615
621
  structure.answers = qaAnswers[j].answers;
616
622
  structure.userAnswer = ms;
617
- structure.linkType = qaAnswers[j].linkType,
618
- structure.linkquestionenabled = requestSection[i].linkquestionenabled,
619
- structure.parentanswer = requestSection[i].parentanswer,
620
- structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
621
- structure.descriptivetype = qaAnswers[j].descriptivetype,
622
- structure.redo = qaAnswers[j]?.redo,
623
+ structure.linkType = qaAnswers[j].linkType;
624
+ structure.linkquestionenabled = requestSection[i].linkquestionenabled;
625
+ structure.parentanswer = requestSection[i].parentanswer;
626
+ structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
627
+ structure.descriptivetype = qaAnswers[j].descriptivetype;
628
+ if ( qaAnswers[j]?.redo ) {
629
+ structure.redo = false;
630
+ }
623
631
  newArray.push( structure );
624
632
  } else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
625
633
  let qaans = qaAnswers[j].answers;
@@ -658,12 +666,14 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
658
666
  structure.remarks = requestSection[i].remarks;
659
667
  structure.answers = qaAnswers[j].answers;
660
668
  structure.userAnswer = mcmo;
661
- structure.linkType = qaAnswers[j].linkType,
662
- structure.linkquestionenabled = requestSection[i].linkquestionenabled,
663
- structure.parentanswer = requestSection[i].parentanswer,
664
- structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
665
- structure.descriptivetype = qaAnswers[j].descriptivetype,
666
- structure.redo = qaAnswers[j]?.redo,
669
+ structure.linkType = qaAnswers[j].linkType;
670
+ structure.linkquestionenabled = requestSection[i].linkquestionenabled;
671
+ structure.parentanswer = requestSection[i].parentanswer;
672
+ structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
673
+ structure.descriptivetype = qaAnswers[j].descriptivetype;
674
+ if ( qaAnswers[j]?.redo ) {
675
+ structure.redo = false;
676
+ }
667
677
  newArray.push( structure );
668
678
  } else if ( qaAnswers[j].answerType == 'multipleImage' ) {
669
679
  let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
@@ -707,12 +717,14 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
707
717
  structure.remarks = requestSection[i].remarks;
708
718
  structure.answers = qaAnswers[j].answers;
709
719
  structure.userAnswer = mcmi;
710
- structure.linkType = qaAnswers[j].linkType,
711
- structure.linkquestionenabled = requestSection[i].linkquestionenabled,
712
- structure.parentanswer = requestSection[i].parentanswer,
713
- structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
714
- structure.descriptivetype = qaAnswers[j].descriptivetype,
715
- structure.redo = qaAnswers[j]?.redo,
720
+ structure.linkType = qaAnswers[j].linkType;
721
+ structure.linkquestionenabled = requestSection[i].linkquestionenabled;
722
+ structure.parentanswer = requestSection[i].parentanswer;
723
+ structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
724
+ structure.descriptivetype = qaAnswers[j].descriptivetype;
725
+ if ( qaAnswers[j]?.redo ) {
726
+ structure.redo = false;
727
+ }
716
728
  newArray.push( structure );
717
729
  } else {
718
730
  let des = [];
@@ -751,12 +763,14 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
751
763
  structure.remarks = requestSection[i].remarks;
752
764
  structure.answers = qaAnswers[j].answers;
753
765
  structure.userAnswer = des;
754
- structure.linkType = qaAnswers[j].linkType,
755
- structure.linkquestionenabled = requestSection[i].linkquestionenabled,
756
- structure.parentanswer = requestSection[i].parentanswer,
757
- structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
758
- structure.descriptivetype = qaAnswers[j].descriptivetype,
759
- structure.redo = qaAnswers[j]?.redo,
766
+ structure.linkType = qaAnswers[j].linkType;
767
+ structure.linkquestionenabled = requestSection[i].linkquestionenabled;
768
+ structure.parentanswer = requestSection[i].parentanswer;
769
+ structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
770
+ structure.descriptivetype = qaAnswers[j].descriptivetype;
771
+ if ( qaAnswers[j]?.redo ) {
772
+ structure.redo = false;
773
+ }
760
774
  newArray.push( structure );
761
775
  }
762
776
  }
@@ -1138,7 +1152,7 @@ export async function submitChecklist( req, res ) {
1138
1152
  } );
1139
1153
  } );
1140
1154
  let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
1141
- if ( updatechecklist ) {
1155
+ if ( updatechecklist?.modifiedCount > 0 ) {
1142
1156
  if ( checklistDetails && checklistDetails.allowedMultiSubmit && requestData.submittype == 'submit' ) {
1143
1157
  let currentTime;
1144
1158
  let date = getchecklist[0].date_string +' '+ getchecklist[0].scheduleEndTime;
@@ -1158,11 +1172,14 @@ export async function submitChecklist( req, res ) {
1158
1172
  let logInsertData = {
1159
1173
  store_id: getchecklist[0].store_id,
1160
1174
  storeName: getchecklist[0].storeName,
1161
- action: 'submitted',
1162
- checklistId: getchecklist[0].checkListId,
1175
+ action: requestData?.submittype === 'draft' ? 'saved' : 'submitted',
1176
+ checklistId: getchecklist[0].sourceCheckList_id,
1177
+ processedChecklistId: getchecklist[0]._id,
1163
1178
  checkListName: getchecklist[0].checkListName,
1179
+ checkListType: getchecklist[0].checkListType,
1164
1180
  client_id: req.user.clientId,
1165
1181
  };
1182
+
1166
1183
  await checklistLogs.create( logInsertData );
1167
1184
  // let time = dayjs().format( 'HH:mm:ss' );
1168
1185
  // let [ hours, minutes ] = time.split( ':' ).map( Number );
@@ -1231,7 +1248,7 @@ export async function submitTask( req, res ) {
1231
1248
  }
1232
1249
 
1233
1250
  // eslint-disable-next-line camelcase
1234
- const { checklistStatus, storeName, userEmail, checkListName, store_id, checkListId } = checklist;
1251
+ const { checklistStatus, storeName, userEmail, checkListName, store_id } = checklist;
1235
1252
 
1236
1253
  if ( checklistStatus === 'open' ) {
1237
1254
  return res.sendError( 'Checklist is in open status. Please start.', 400 );
@@ -1291,7 +1308,9 @@ export async function submitTask( req, res ) {
1291
1308
  store_id,
1292
1309
  storeName,
1293
1310
  action: submittype === 'draft' ? 'saved' : 'submitted',
1294
- checklistId: checkListId,
1311
+ checklistId: checklist.sourceCheckList_id,
1312
+ processedChecklistId: checklist._id,
1313
+ checkListType: checklist.checkListType,
1295
1314
  checkListName,
1296
1315
  client_id: user.clientId,
1297
1316
  };
@@ -1329,6 +1348,7 @@ async function updateOpenSearch( user, data ) {
1329
1348
  action: 'OpenSearch insert Triggered',
1330
1349
  checklistId: getchecklist[0].checkListId,
1331
1350
  checkListName: getchecklist[0].checkListName,
1351
+ checkListType: getchecklist[0].checkListType,
1332
1352
  client_id: user.clientId,
1333
1353
  };
1334
1354
  await checklistLogs.create( logInsertData );
@@ -1348,6 +1368,7 @@ async function updateOpenSearch( user, data ) {
1348
1368
  action: 'OpenSearch inserted Successfully',
1349
1369
  checklistId: getchecklist[0].checkListId,
1350
1370
  checkListName: getchecklist[0].checkListName,
1371
+ checkListType: getchecklist[0].checkListType,
1351
1372
  client_id: user.clientId,
1352
1373
  };
1353
1374
  await checklistLogs.create( logInsertData );
@@ -1374,6 +1395,7 @@ async function updateOpenSearchTask( user, data ) {
1374
1395
  action: 'OpenSearch insert Triggered',
1375
1396
  checklistId: getchecklist[0].checkListId,
1376
1397
  checkListName: getchecklist[0].checkListName,
1398
+ checkListType: getchecklist[0].checkListType,
1377
1399
  client_id: user.clientId,
1378
1400
  };
1379
1401
  await checklistLogs.create( logInsertData );
@@ -1393,6 +1415,7 @@ async function updateOpenSearchTask( user, data ) {
1393
1415
  action: 'OpenSearch inserted Successfully',
1394
1416
  checklistId: getchecklist[0].checkListId,
1395
1417
  checkListName: getchecklist[0].checkListName,
1418
+ checkListType: getchecklist[0].checkListType,
1396
1419
  client_id: user.clientId,
1397
1420
  };
1398
1421
  await checklistLogs.create( logInsertData );
@@ -1767,6 +1790,7 @@ export async function questionList( req, res ) {
1767
1790
  getchecklist: { $ifNull: [ '$getchecklist', '' ] },
1768
1791
  userEmail: { $ifNull: [ '$userEmail', '' ] },
1769
1792
  storeName: { $ifNull: [ '$storeName', '' ] },
1793
+ redoStatus: { $ifNull: [ '$redoStatus', false ] },
1770
1794
  },
1771
1795
  } );
1772
1796
 
@@ -28,13 +28,14 @@ export const checklist = async ( req, res ) => {
28
28
  let offset = parseInt( req.query.offset - 1 ) || 0;
29
29
  let page = offset * limit;
30
30
  let query = [];
31
-
31
+ console.log( req.user.email, 'email' );
32
32
  query.push(
33
33
  {
34
34
  $match: {
35
35
  type: 'checklist',
36
36
  client_id: req.query.clientId,
37
37
  isdeleted: false,
38
+ ...( req.user.userType == 'client' && req.user.role != 'superadmin' ) ? { owner: { $in: [ req.user.email ] } } : {},
38
39
  },
39
40
  },
40
41
  );
@@ -948,6 +949,7 @@ export const updateConfigure =async ( req, res ) => {
948
949
  allowOnce: inputBody?.checkListDetails?.allowOnce || false,
949
950
  approver: inputBody?.checkListDetails?.approver || [],
950
951
  remainder: inputBody?.checkListDetails?.remainder || [],
952
+ owner: inputBody?.checkListDetails?.owner || [],
951
953
  };
952
954
 
953
955
  if ( inputBody?.checkListDetails?.approver.length ) {
@@ -1173,8 +1175,17 @@ export const updatePublish = async ( req, res ) => {
1173
1175
  return res.sendError( 'no data found', 204 );
1174
1176
  }
1175
1177
 
1178
+ if ( getCheckDetails?.publishDate ) {
1179
+ let date = dayjs();
1180
+ let diff = date.diff( dayjs.utc( getCheckDetails?.publishDate ), 'minutes' );
1181
+ if ( diff < 5 ) {
1182
+ let mins = ( 5 - diff ) > 1 ? 'minutes' : 'minute';
1183
+ return res.sendError( `Please try after ${5 - diff} ${mins}`, 400 );
1184
+ }
1185
+ }
1186
+
1176
1187
  getCheckDetails.publish = req.body.publish;
1177
- getCheckDetails.publishDate = new Date();
1188
+ getCheckDetails.publishDate = req.body.publish ? new Date() : getCheckDetails?.publishDate;
1178
1189
  let currentDate = dayjs();
1179
1190
  if ( !req.body.publish ) {
1180
1191
  await processedchecklistConfig.deleteMany( { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId } );
@@ -34,5 +34,3 @@ export const getClientCount = ( query = {} ) => {
34
34
  export const create = ( data = {} ) => {
35
35
  return model.processedchecklistModel.create( data );
36
36
  };
37
-
38
-