tango-app-api-trax 3.2.1 → 3.3.1-airtalai-0

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.
@@ -113,7 +113,7 @@ export async function startChecklist( req, res ) {
113
113
  return res.sendError( 'already check list started', 400 );
114
114
  }
115
115
 
116
- logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
116
+ logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName || ''}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
117
117
  let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
118
118
  let updateQuery = {};
119
119
  updateQuery._id = new ObjectId( requestData.processedcheckListId );
@@ -149,10 +149,14 @@ export async function startChecklist( req, res ) {
149
149
  }
150
150
 
151
151
  let updateData = {};
152
- let storeTimeZone = await storeService.findOne( { storeName: getBeforeChecklist[0].storeName }, { 'storeProfile.timeZone': 1 } );
153
152
  let currentDateTime;
154
- if ( storeTimeZone?.storeProfile?.timeZone ) {
155
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
153
+ if ( getBeforeChecklist[0].storeName && getBeforeChecklist[0].storeName!='' ) {
154
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
155
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
156
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
157
+ } else {
158
+ currentDateTime = dayjs();
159
+ }
156
160
  } else {
157
161
  currentDateTime = dayjs();
158
162
  }
@@ -171,6 +175,8 @@ export async function startChecklist( req, res ) {
171
175
  findQuery.push( {
172
176
  $project: {
173
177
  checkListName: { $ifNull: [ '$checkListName', '' ] },
178
+ coverage: { $ifNull: [ '$coverage', '' ] },
179
+ client_id: { $ifNull: [ '$client_id', '' ] },
174
180
  scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
175
181
  scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
176
182
  scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
@@ -185,7 +191,13 @@ export async function startChecklist( req, res ) {
185
191
  $cond: {
186
192
  if: { $eq: [ '$client_id', '11' ] },
187
193
  then: false,
188
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
194
+ else: {
195
+ '$cond': {
196
+ 'if': { '$eq': [ '$coverage', 'user' ] },
197
+ 'then': false,
198
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
199
+ },
200
+ },
189
201
  },
190
202
  },
191
203
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
@@ -207,17 +219,19 @@ export async function startChecklist( req, res ) {
207
219
  } );
208
220
  } );
209
221
  let logInsertData = {
210
- store_id: getBeforeChecklist[0].store_id,
211
- storeName: getBeforeChecklist[0].storeName,
222
+ store_id: getBeforeChecklist[0]?.store_id || '',
223
+ storeName: getBeforeChecklist[0]?.storeName || '',
212
224
  action: 'started',
213
225
  checklistId: getBeforeChecklist[0].sourceCheckList_id,
214
226
  processedChecklistId: getBeforeChecklist[0]._id,
215
227
  checkListName: getBeforeChecklist[0].checkListName,
216
228
  type: getBeforeChecklist[0].checkListType,
217
229
  client_id: req.user.clientId,
230
+ userEmail: getBeforeChecklist[0].userEmail || '',
231
+ userName: getBeforeChecklist[0].userName || '',
232
+ coverage: getBeforeChecklist[0].coverage || '',
218
233
  };
219
234
  await checklistLogs.create( logInsertData );
220
-
221
235
  let getchecklist = getupdatedchecklist;
222
236
  let questions = [];
223
237
  function processQuestion( question, section, questions, nested=false ) {
@@ -253,6 +267,7 @@ export async function startChecklist( req, res ) {
253
267
  return res.sendError( 'something went wrong please try again', 500 );
254
268
  }
255
269
  } catch ( e ) {
270
+ console.log( 'e =>', e );
256
271
  logger.error( { function: 'startChecklist', error: e, body: req.body } );
257
272
  return res.sendError( e, 500 );
258
273
  }
@@ -356,7 +371,13 @@ export async function startTask( req, res ) {
356
371
  $cond: {
357
372
  if: { $eq: [ '$client_id', '11' ] },
358
373
  then: false,
359
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
374
+ else: {
375
+ '$cond': {
376
+ 'if': { '$eq': [ '$coverage', 'user' ] },
377
+ 'then': false,
378
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
379
+ },
380
+ },
360
381
  },
361
382
  },
362
383
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
@@ -689,6 +710,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
689
710
  structure.parentanswer = requestSection[i].parentanswer;
690
711
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
691
712
  structure.descriptivetype = qaAnswers[j].descriptivetype;
713
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
692
714
  if ( qaAnswers[j]?.taskId ) {
693
715
  structure.taskId = qaAnswers[j]?.taskId;
694
716
  structure.task = true;
@@ -740,6 +762,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
740
762
  structure.parentanswer = requestSection[i].parentanswer;
741
763
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
742
764
  structure.descriptivetype = qaAnswers[j].descriptivetype;
765
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
743
766
  if ( qaAnswers[j]?.taskId ) {
744
767
  structure.taskId = qaAnswers[j]?.taskId;
745
768
  structure.task = true;
@@ -795,6 +818,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
795
818
  structure.parentanswer = requestSection[i].parentanswer;
796
819
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
797
820
  structure.descriptivetype = qaAnswers[j].descriptivetype;
821
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
798
822
  if ( qaAnswers[j]?.taskId ) {
799
823
  structure.taskId = qaAnswers[j]?.taskId;
800
824
  structure.task = true;
@@ -855,6 +879,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
855
879
  structure.parentanswer = requestSection[i].parentanswer;
856
880
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
857
881
  structure.descriptivetype = qaAnswers[j].descriptivetype;
882
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
858
883
  if ( qaAnswers[j]?.taskId ) {
859
884
  structure.taskId = qaAnswers[j]?.taskId;
860
885
  structure.task = true;
@@ -913,6 +938,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
913
938
  structure.parentanswer = requestSection[i].parentanswer;
914
939
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
915
940
  structure.descriptivetype = qaAnswers[j].descriptivetype;
941
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
916
942
  if ( qaAnswers[j]?.taskId ) {
917
943
  structure.taskId = qaAnswers[j]?.taskId;
918
944
  structure.task = true;
@@ -970,7 +996,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
970
996
  if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
971
997
  let sampleData = reqAnswers[0];
972
998
  CLQAnswers.forEach( ( section ) => {
973
- console.log( section, 'section' );
974
999
  let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
975
1000
  if ( requestSection.length ) {
976
1001
  requestSection.forEach( ( item ) => item.section_id = section.section_id );
@@ -981,6 +1006,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
981
1006
  data.answerType = question.answerType;
982
1007
  data.qno = question.qno;
983
1008
  data.qname = question.qname;
1009
+ data.oldQname = question?.oldQname || question.qname;
984
1010
  data.answer = 'null';
985
1011
  data.remarks = '';
986
1012
  data.validationAnswer = '';
@@ -1002,6 +1028,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1002
1028
  data.answerType = ele.answerType;
1003
1029
  data.qno = ele.qno;
1004
1030
  data.qname = ele.qname;
1031
+ data.oldQname = ele?.oldQname || ele.qname;
1005
1032
  data.answer = 'null';
1006
1033
  data.remarks = '';
1007
1034
  data.validationAnswer = '';
@@ -1074,13 +1101,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1074
1101
  structure.parentanswer = requestSection[i].parentanswer;
1075
1102
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1076
1103
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1104
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
1105
+ structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
1077
1106
  if ( qaAnswers[j]?.taskId ) {
1078
1107
  structure.taskId = qaAnswers[j]?.taskId;
1079
1108
  structure.task = true;
1080
1109
  }
1081
1110
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1082
1111
  structure.redo = false;
1083
- } else if ( requestData.submittype === 'draft' ) {
1112
+ } else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
1084
1113
  structure.redo = qaAnswers[j]?.redo;
1085
1114
  }
1086
1115
  if ( qaAnswers[j]?.redoComment ) {
@@ -1125,13 +1154,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1125
1154
  structure.parentanswer = requestSection[i].parentanswer;
1126
1155
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1127
1156
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1157
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
1158
+ structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
1128
1159
  if ( qaAnswers[j]?.taskId ) {
1129
1160
  structure.taskId = qaAnswers[j]?.taskId;
1130
1161
  structure.task = true;
1131
1162
  }
1132
1163
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1133
1164
  structure.redo = false;
1134
- } else if ( requestData.submittype === 'draft' ) {
1165
+ } else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
1135
1166
  structure.redo = qaAnswers[j]?.redo;
1136
1167
  }
1137
1168
  if ( qaAnswers[j]?.redoComment ) {
@@ -1180,13 +1211,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1180
1211
  structure.parentanswer = requestSection[i].parentanswer;
1181
1212
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1182
1213
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1214
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
1215
+ structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
1183
1216
  if ( qaAnswers[j]?.taskId ) {
1184
1217
  structure.taskId = qaAnswers[j]?.taskId;
1185
1218
  structure.task = true;
1186
1219
  }
1187
1220
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1188
1221
  structure.redo = false;
1189
- } else if ( requestData.submittype === 'draft' ) {
1222
+ } else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
1190
1223
  structure.redo = qaAnswers[j]?.redo;
1191
1224
  }
1192
1225
  if ( qaAnswers[j]?.redoComment ) {
@@ -1240,13 +1273,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1240
1273
  structure.parentanswer = requestSection[i].parentanswer;
1241
1274
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1242
1275
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1276
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
1277
+ structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
1243
1278
  if ( qaAnswers[j]?.taskId ) {
1244
1279
  structure.taskId = qaAnswers[j]?.taskId;
1245
1280
  structure.task = true;
1246
1281
  }
1247
1282
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1248
1283
  structure.redo = false;
1249
- } else if ( requestData.submittype === 'draft' ) {
1284
+ } else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
1250
1285
  structure.redo = qaAnswers[j]?.redo;
1251
1286
  }
1252
1287
  if ( qaAnswers[j]?.redoComment ) {
@@ -1298,13 +1333,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1298
1333
  structure.parentanswer = requestSection[i].parentanswer;
1299
1334
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1300
1335
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1336
+ // structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
1337
+ structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
1301
1338
  if ( qaAnswers[j]?.taskId ) {
1302
1339
  structure.taskId = qaAnswers[j]?.taskId;
1303
1340
  structure.task = true;
1304
1341
  }
1305
1342
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1306
1343
  structure.redo = false;
1307
- } else if ( requestData.submittype === 'draft' ) {
1344
+ } else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
1308
1345
  structure.redo = qaAnswers[j]?.redo;
1309
1346
  }
1310
1347
  if ( qaAnswers[j]?.redoComment ) {
@@ -1700,12 +1737,18 @@ export async function submitChecklist( req, res ) {
1700
1737
  updateQuery._id = new ObjectId( requestData.processedcheckListId );
1701
1738
  updateQuery.userId = req.user._id;
1702
1739
  updateQuery.date_string = requestData.date;
1703
- let storeTimeZone = await storeService.findOne( { storeName: getchecklist[0].storeName }, { 'storeProfile.timeZone': 1 } );
1740
+
1704
1741
  let currentDateTime;
1705
- if ( storeTimeZone?.storeProfile?.timeZone ) {
1706
- currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1742
+ let storeTimeZone;
1743
+ if ( getchecklist[0].storeName && getchecklist[0].storeName !='' ) {
1744
+ storeTimeZone = await storeService.findOne( { storeName: { $regex: getchecklist[0].storeName, $options: 'i' }, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
1745
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
1746
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1747
+ } else {
1748
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
1749
+ }
1707
1750
  } else {
1708
- currentDateTime = dayjs();
1751
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
1709
1752
  }
1710
1753
  let updateData = {};
1711
1754
  let flagCount = QuestionFlag( req, res );
@@ -1749,8 +1792,8 @@ export async function submitChecklist( req, res ) {
1749
1792
  }
1750
1793
 
1751
1794
  let logInsertData = {
1752
- store_id: getchecklist[0].store_id,
1753
- storeName: getchecklist[0].storeName,
1795
+ store_id: getchecklist[0].store_id || '',
1796
+ storeName: getchecklist[0].storeName || '',
1754
1797
  action: requestData?.submittype === 'draft' ? 'saved' : 'submitted',
1755
1798
  checklistId: getchecklist[0].sourceCheckList_id,
1756
1799
  processedChecklistId: getchecklist[0]._id,
@@ -1758,8 +1801,11 @@ export async function submitChecklist( req, res ) {
1758
1801
  type: getchecklist[0].checkListType,
1759
1802
  client_id: req.user.clientId,
1760
1803
  redoStatus: requestData?.redoStatus ? true : false,
1804
+ userEmail: getchecklist[0].userEmail || '',
1805
+ userName: getchecklist[0].userName || '',
1806
+ coverage: getchecklist[0].coverage || '',
1761
1807
  };
1762
-
1808
+ console.log( 'logInsertData=>', logInsertData );
1763
1809
  await checklistLogs.create( logInsertData );
1764
1810
  // let time = dayjs().format( 'HH:mm:ss' );
1765
1811
  // let [ hours, minutes ] = time.split( ':' ).map( Number );
@@ -1792,7 +1838,9 @@ export async function submitChecklist( req, res ) {
1792
1838
  // createdAt: createdAtDate,
1793
1839
  // };
1794
1840
  // await detectionService.create( detectionData );
1795
- updateOpenSearch( req.user, requestData );
1841
+ if ( requestData.submittype == 'submit' ) {
1842
+ updateOpenSearch( req.user, requestData );
1843
+ }
1796
1844
 
1797
1845
  return res.sendSuccess( 'Checklist Updated Successfully' );
1798
1846
  } else {
@@ -1956,7 +2004,9 @@ export async function submitTask( req, res ) {
1956
2004
  };
1957
2005
  await checklistLogs.create( logInsertData );
1958
2006
 
1959
- updateOpenSearchTask( user, requestData );
2007
+ if ( submittype == 'submit' ) {
2008
+ updateOpenSearchTask( user, requestData );
2009
+ }
1960
2010
 
1961
2011
  return res.sendSuccess( 'Task Updated Successfully' );
1962
2012
  } else {
@@ -1991,6 +2041,9 @@ async function updateOpenSearch( user, data ) {
1991
2041
  checkListName: getchecklist[0].checkListName,
1992
2042
  type: getchecklist[0].checkListType,
1993
2043
  client_id: user.clientId,
2044
+ userEmail: getchecklist[0].userEmail || '',
2045
+ userName: getchecklist[0].userName || '',
2046
+ coverage: getchecklist[0].coverage || '',
1994
2047
  };
1995
2048
  await checklistLogs.create( logInsertData );
1996
2049
  const requestOptions = {
@@ -2012,6 +2065,9 @@ async function updateOpenSearch( user, data ) {
2012
2065
  checkListName: getchecklist[0].checkListName,
2013
2066
  type: getchecklist[0].checkListType,
2014
2067
  client_id: user.clientId,
2068
+ userEmail: getchecklist[0].userEmail || '',
2069
+ userName: getchecklist[0].userName || '',
2070
+ coverage: getchecklist[0].coverage || '',
2015
2071
  };
2016
2072
  await checklistLogs.create( logInsertData );
2017
2073
  }
@@ -2040,6 +2096,9 @@ async function updateOpenSearchTask( user, data ) {
2040
2096
  checkListName: getchecklist[0].checkListName,
2041
2097
  type: getchecklist[0].checkListType,
2042
2098
  client_id: user.clientId,
2099
+ userEmail: getchecklist[0].userEmail || '',
2100
+ userName: getchecklist[0].userName || '',
2101
+ coverage: getchecklist[0].coverage || '',
2043
2102
  };
2044
2103
  await checklistLogs.create( logInsertData );
2045
2104
  const requestOptions = {
@@ -2061,6 +2120,9 @@ async function updateOpenSearchTask( user, data ) {
2061
2120
  checkListName: getchecklist[0].checkListName,
2062
2121
  type: getchecklist[0].checkListType,
2063
2122
  client_id: user.clientId,
2123
+ userEmail: getchecklist[0].userEmail || '',
2124
+ userName: getchecklist[0].userName || '',
2125
+ coverage: getchecklist[0].coverage || '',
2064
2126
  };
2065
2127
  await checklistLogs.create( logInsertData );
2066
2128
  }
@@ -2153,17 +2215,24 @@ export async function dashboard( req, res ) {
2153
2215
  export async function dashboardv1( req, res ) {
2154
2216
  try {
2155
2217
  // eslint-disable-next-line camelcase
2156
- const { store_id, date } = req.query;
2218
+ // const { store_id, date } = req.query;
2219
+ const { date } = req.query;
2157
2220
  const userId = req.user._id;
2158
2221
 
2222
+ // //Get User Based Checklist //
2223
+ const clientId = { client_id: req.user.clientId };
2224
+ const storeMatch = { $or: [ { store_id: { $eq: req.query.store_id || '' } }, { store_id: { $eq: '' } } ] };
2225
+ // //End: Get User Based Checklist////
2226
+
2159
2227
  const baseMatch = {
2160
2228
  // eslint-disable-next-line camelcase
2161
- store_id,
2229
+ // store_id,
2162
2230
  userId,
2163
2231
  date_string: date,
2164
2232
  timeFlagStatus: true,
2233
+ ...clientId,
2234
+ ...storeMatch,
2165
2235
  };
2166
-
2167
2236
  const buildPipeline = ( matchExtraConditions = {} ) => [
2168
2237
  { $match: { ...baseMatch, ...matchExtraConditions } },
2169
2238
  {
@@ -2219,6 +2288,7 @@ export async function dashboardv1( req, res ) {
2219
2288
 
2220
2289
  return res.sendSuccess( totalResult );
2221
2290
  } catch ( e ) {
2291
+ console.log( 'v1 =>', e );
2222
2292
  logger.error( { function: 'dashboardv1', error: e, body: req.body } );
2223
2293
  return res.sendError( e, 500 );
2224
2294
  }
@@ -2287,7 +2357,13 @@ export async function checklist( req, res ) {
2287
2357
  $cond: {
2288
2358
  if: { $eq: [ '$client_id', '11' ] },
2289
2359
  then: false,
2290
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2360
+ else: {
2361
+ '$cond': {
2362
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2363
+ 'then': false,
2364
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2365
+ },
2366
+ },
2291
2367
  },
2292
2368
  },
2293
2369
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -2319,19 +2395,26 @@ export async function checklist( req, res ) {
2319
2395
  export async function checklistv1( req, res ) {
2320
2396
  try {
2321
2397
  // eslint-disable-next-line camelcase
2322
- const { store_id, date, checklistStatus, searchValue } = req.query;
2398
+ // const { store_id, date, checklistStatus, searchValue } = req.query;
2399
+ const { date, checklistStatus, searchValue } = req.query;
2323
2400
  const userId = req.user._id;
2324
2401
 
2325
- const buildPipeline = ( matchExtraConditions = [], type ) => {
2402
+ // Get User Based Checklist //
2403
+ const clientId = { client_id: req.user.clientId };
2404
+ const storeMatch = { $or: [ { store_id: { $eq: req.query.store_id || '' } }, { store_id: { $eq: '' } } ] };
2405
+ // End: Get User Based Checklist////
2406
+
2407
+ const buildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
2326
2408
  const matchConditions = [
2327
2409
  // eslint-disable-next-line camelcase
2328
- { store_id },
2410
+ // { store_id },
2329
2411
  { userId },
2330
2412
  { date_string: date },
2331
2413
  { timeFlagStatus: true },
2332
2414
  ...matchExtraConditions,
2415
+ clientId,
2416
+ storeMatch,
2333
2417
  ];
2334
-
2335
2418
  if ( checklistStatus ) {
2336
2419
  matchConditions.push( { checklistStatus } );
2337
2420
  }
@@ -2358,7 +2441,13 @@ export async function checklistv1( req, res ) {
2358
2441
  $cond: {
2359
2442
  if: { $eq: [ '$client_id', '11' ] },
2360
2443
  then: false,
2361
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2444
+ else: {
2445
+ '$cond': {
2446
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2447
+ 'then': false,
2448
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2449
+ },
2450
+ },
2362
2451
  },
2363
2452
  },
2364
2453
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -2370,6 +2459,10 @@ export async function checklistv1( req, res ) {
2370
2459
  redoStatus: { $ifNull: [ '$redoStatus', false ] },
2371
2460
  type: { $ifNull: [ '$checkListType', '' ] },
2372
2461
  priorityType: { $ifNull: [ '$priorityType', '' ] },
2462
+ ...projectExtraConditions,
2463
+ client_id: { $ifNull: [ '$client_id', '' ] },
2464
+ coverage: { $ifNull: [ '$coverage', '' ] },
2465
+ taskType: { $ifNull: [ '$planoType', '' ] },
2373
2466
  },
2374
2467
  },
2375
2468
  ];
@@ -2378,8 +2471,8 @@ export async function checklistv1( req, res ) {
2378
2471
  };
2379
2472
 
2380
2473
  const [ checklistResult, taskResult ] = await Promise.allSettled( [
2381
- processedchecklist.aggregate( buildPipeline( [ { checkListType: 'custom' } ], 'checklist' ) ),
2382
- processedTask.aggregate( buildPipeline( [], 'task' ) ),
2474
+ processedchecklist.aggregate( buildPipeline( [ { checkListType: 'custom' } ], { isPlano: 1, planoId: 1, planoType: 1 } ) ),
2475
+ processedTask.aggregate( buildPipeline( [], { isPlano: 1, planoId: 1, planoType: 1 } ) ),
2383
2476
  ] );
2384
2477
 
2385
2478
  const checklistData = checklistResult.status === 'fulfilled' ? checklistResult.value : [];
@@ -2388,7 +2481,7 @@ export async function checklistv1( req, res ) {
2388
2481
  const totalData = [ ...checklistData, ...taskData ];
2389
2482
 
2390
2483
  if ( !totalData.length ) {
2391
- return res.sendError( { error: 'No Data Found' }, 204 );
2484
+ return res.sendSuccess( { count: 0, data: [] } );
2392
2485
  }
2393
2486
 
2394
2487
  const getSortingParams = ( status ) => {
@@ -2448,7 +2541,13 @@ export async function questionList( req, res ) {
2448
2541
  $cond: {
2449
2542
  if: { $eq: [ '$client_id', '11' ] },
2450
2543
  then: false,
2451
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2544
+ else: {
2545
+ '$cond': {
2546
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2547
+ 'then': false,
2548
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2549
+ },
2550
+ },
2452
2551
  },
2453
2552
  },
2454
2553
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -2457,6 +2556,7 @@ export async function questionList( req, res ) {
2457
2556
  userEmail: { $ifNull: [ '$userEmail', '' ] },
2458
2557
  storeName: { $ifNull: [ '$storeName', '' ] },
2459
2558
  redoStatus: { $ifNull: [ '$redoStatus', false ] },
2559
+ rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
2460
2560
  },
2461
2561
  } );
2462
2562
 
@@ -2476,7 +2576,11 @@ export async function questionList( req, res ) {
2476
2576
  if ( question.answerType == 'multiplechoicemultiple' ) {
2477
2577
  let checkvalidation = null;
2478
2578
  if ( answer.validationAnswer && answer.validationAnswer !='' ) {
2479
- checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
2579
+ if ( answer.validationType != 'Descriptive Answer' ) {
2580
+ checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
2581
+ } else {
2582
+ checkvalidation = answer.validationAnswer;
2583
+ }
2480
2584
  }
2481
2585
  Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
2482
2586
  getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
@@ -2753,7 +2857,13 @@ export async function taskQuestionList( req, res ) {
2753
2857
  $cond: {
2754
2858
  if: { $eq: [ '$client_id', '11' ] },
2755
2859
  then: false,
2756
- else: { $ifNull: [ '$allowedStoreLocation', false ] },
2860
+ else: {
2861
+ '$cond': {
2862
+ 'if': { '$eq': [ '$coverage', 'user' ] },
2863
+ 'then': false,
2864
+ 'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
2865
+ },
2866
+ },
2757
2867
  },
2758
2868
  },
2759
2869
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
@@ -3070,7 +3180,7 @@ export async function login( req, res ) {
3070
3180
  return res.sendError( `User mail not Exists`, 401 );
3071
3181
  }
3072
3182
  if ( !result.isActive ) {
3073
- return res.sendError( 'The user has been unauthorized to login', 401 );
3183
+ return res.sendError( 'Your account is currently inactive. Please contact your admin.', 401 );
3074
3184
  }
3075
3185
  if ( inputData.otp ) {
3076
3186
  const otpMatching = await findOTP( { email: result.email, type: 'login', otp: inputData.otp } );
@@ -3282,3 +3392,53 @@ export async function checkVersion( req, res ) {
3282
3392
  return res.sendError( e, 500 );
3283
3393
  }
3284
3394
  }
3395
+
3396
+ export async function clientConfig( req, res ) {
3397
+ try {
3398
+ let requestData = req.body;
3399
+ if ( requestData.clientId && requestData.clientId !='' ) {
3400
+ let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1, traxBlockMobileTimeUpdate: 1 } );
3401
+ // console.log( ' getClientData=>', getClientData );
3402
+ if ( getClientData ) {
3403
+ return res.sendSuccess( getClientData );
3404
+ } else {
3405
+ return res.sendError( 'Invalid clientId', 400 );
3406
+ }
3407
+ } else {
3408
+ return res.sendError( 'clientId is Required', 400 );
3409
+ }
3410
+ } catch ( e ) {
3411
+ console.log( 'e =>', e );
3412
+ logger.error( { error: e, function: 'clientConfig' } );
3413
+ return res.sendError( e, 500 );
3414
+ }
3415
+ }
3416
+
3417
+ export async function updatePlanoStatus( req, res ) {
3418
+ try {
3419
+ if ( !req.body.id ) {
3420
+ return res.sendError( 'Processed checklist id is required' );
3421
+ }
3422
+ if ( !req.body.status ) {
3423
+ return res.sendError( 'status is required' );
3424
+ }
3425
+ let processCheckDetails = await processedchecklist.findOne( { _id: req.body.id } );
3426
+ if ( !processCheckDetails ) {
3427
+ return res.sendError( 'No data found', 204 );
3428
+ }
3429
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: processCheckDetails.storeName, $options: 'i' }, clientId: processCheckDetails.client_id }, { 'storeProfile.timeZone': 1 } );
3430
+ let currentDateTime;
3431
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
3432
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
3433
+ } else {
3434
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
3435
+ }
3436
+ let submitTimeString = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
3437
+ await processedchecklist.updateOne( { _id: req.body.id }, { checklistStatus: req.body.status, ...( req.body.status == 'inprogress' ) ? { startTime_string: submitTimeString } : { submitTime_string: submitTimeString } } );
3438
+ return res.sendSuccess( 'Status updated Successfully' );
3439
+ } catch ( e ) {
3440
+ logger.error( { error: e, function: 'updatePlanoStatus' } );
3441
+ return res.sendError( e, 500 );
3442
+ }
3443
+ }
3444
+