tango-app-api-task 3.2.1 → 3.3.1-airtelai-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.
@@ -1,6 +1,6 @@
1
1
  import * as traxApprover from '../service/approver.service.js';
2
2
  import * as processedTask from '../service/processedTaskList.service.js';
3
- import { logger } from 'tango-app-api-middleware';
3
+ import { logger } from 'tango-app-api-middleware'; // getChecklistUsers
4
4
  import * as processedChecklist from '../service/processedChecklist.service.js';
5
5
  import * as checklistLog from '../service/checklistLog.service.js';
6
6
  import mongoose from 'mongoose';
@@ -46,14 +46,21 @@ export const overallCardsV1 = async ( req, res ) => {
46
46
  },
47
47
  };
48
48
 
49
+ let requestData = req.body;
50
+ // Get User Based Checklist //
51
+ // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
52
+ // let getUserEmails = await getChecklistUsers( loginUser );
53
+ // End: Get User Based Checklist////
54
+
49
55
  let taskQuery = [
50
56
  {
51
57
  $match: {
52
58
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
53
59
  sourceCheckList_id: { $in: taskIdList },
54
60
  checklistStatus: 'submit',
55
- ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
56
61
  approvalStatus: false,
62
+ // ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
63
+ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
57
64
  },
58
65
  },
59
66
  { ...groupQuery },
@@ -65,8 +72,9 @@ export const overallCardsV1 = async ( req, res ) => {
65
72
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
66
73
  sourceCheckList_id: { $in: checklistIdList },
67
74
  checklistStatus: 'submit',
68
- ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
69
75
  approvalStatus: false,
76
+ // ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
77
+ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
70
78
  },
71
79
  },
72
80
  { ...groupQuery },
@@ -80,7 +88,7 @@ export const overallCardsV1 = async ( req, res ) => {
80
88
  resultData = { taskApproval: { count: taskCount?.[0]?.count || 0 }, checklistApproval: { count: checklistCount?.[0]?.count || 0 } };
81
89
  return res.sendSuccess( { cardData: resultData } );
82
90
  } catch ( error ) {
83
- console.log( 'error =>', error );
91
+ // console.log( 'error =>', error );
84
92
  logger.error( { error: error, function: 'overallCards' } );
85
93
  return res.sendError( error, 500 );
86
94
  }
@@ -151,6 +159,8 @@ export const approvalTableV1 = async ( req, res ) => {
151
159
  ],
152
160
  },
153
161
  },
162
+ coverage: { $first: '$coverage' },
163
+ userName: { $first: '$userName' },
154
164
  },
155
165
  },
156
166
  {
@@ -169,6 +179,8 @@ export const approvalTableV1 = async ( req, res ) => {
169
179
  unApproveCount: 1,
170
180
  storeName: 1,
171
181
  redo: '$_id.redoType',
182
+ coverage: 1,
183
+ userName: 1,
172
184
  },
173
185
  },
174
186
  {
@@ -180,13 +192,20 @@ export const approvalTableV1 = async ( req, res ) => {
180
192
 
181
193
  const promises = [];
182
194
 
195
+ let requestData = req.body;
196
+ // Get User Based Checklist //
197
+ // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
198
+ // let getUserEmails = await getChecklistUsers( loginUser );
199
+ // End: Get User Based Checklist////
200
+
183
201
  if ( [ 'task', 'all' ].includes( req.body.type ) ) {
184
202
  query = [
185
203
  {
186
204
  $match: {
187
205
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
188
206
  sourceCheckList_id: { $in: taskIdList },
189
- ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
207
+ // ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
208
+ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
190
209
  },
191
210
  },
192
211
  ...groupQuery,
@@ -217,7 +236,8 @@ export const approvalTableV1 = async ( req, res ) => {
217
236
  $match: {
218
237
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
219
238
  sourceCheckList_id: { $in: checklistIdList },
220
- ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
239
+ // ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
240
+ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
221
241
  },
222
242
  },
223
243
  ...groupQuery,
@@ -281,11 +301,16 @@ export const activityLogV1 = async ( req, res ) => {
281
301
  let findQuery = [];
282
302
  let findAndQuery = [];
283
303
 
304
+ // Get User Based Checklist //
305
+ // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
306
+ // let getUserEmails = await getChecklistUsers( loginUser );
307
+ // End: Get User Based Checklist////
284
308
 
285
309
  findAndQuery.push(
286
310
  { client_id: requestData.clientId },
287
- { store_id: { $in: requestData.storeId } },
288
311
  { action: { $in: [ 'submitted', 'started' ] } },
312
+ // { store_id: { $in: requestData.storeId } },
313
+ { $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ] },
289
314
  );
290
315
 
291
316
 
@@ -294,6 +319,9 @@ export const activityLogV1 = async ( req, res ) => {
294
319
  $project: {
295
320
  checkListName: 1,
296
321
  storeName: 1,
322
+ userEmail: 1,
323
+ userName: 1,
324
+ coverage: 1,
297
325
  action: 1,
298
326
  createdAt: 1,
299
327
  type: 1,
@@ -338,7 +366,7 @@ export const overallCards = async ( req, res ) => {
338
366
  let resultData = await overallCardsData( requestData );
339
367
  return res.sendSuccess( resultData );
340
368
  } catch ( error ) {
341
- console.log( 'error =>', error );
369
+ // console.log( 'error =>', error );
342
370
  logger.error( { error: error, function: 'overallCards' } );
343
371
  return res.sendError( error, 500 );
344
372
  }
@@ -357,7 +385,7 @@ async function overallCardsData( requestData ) {
357
385
  // resultData.card = cardData;
358
386
  return { cardData: cardData };
359
387
  } catch ( error ) {
360
- console.log( 'error =>', error );
388
+ // console.log( 'error =>', error );
361
389
  logger.error( { error: error, message: data, function: 'overallCardsData' } );
362
390
  }
363
391
  }
@@ -368,7 +396,7 @@ export const approvalTable = async ( req, res ) => {
368
396
  let resultData = await approvalTableData( requestData );
369
397
  return res.sendSuccess( resultData );
370
398
  } catch ( error ) {
371
- console.log( 'error =>', error );
399
+ // console.log( 'error =>', error );
372
400
  logger.error( { error: error, function: 'taskTable' } );
373
401
  return res.sendError( error, 500 );
374
402
  }
@@ -435,7 +463,7 @@ async function approvalTableData( requestData ) {
435
463
  };
436
464
  return tableData;
437
465
  } catch ( error ) {
438
- console.log( 'error =>', error );
466
+ // console.log( 'error =>', error );
439
467
  logger.error( { error: error, message: requestData, function: 'approvalTableData' } );
440
468
  return res.sendError( error, 500 );
441
469
  }
@@ -447,7 +475,7 @@ export const activityLog = async ( req, res ) => {
447
475
  let resultData = await activityLogData( requestData );
448
476
  return res.sendSuccess( resultData );
449
477
  } catch ( error ) {
450
- console.log( 'error =>', error );
478
+ // console.log( 'error =>', error );
451
479
  logger.error( { error: error, function: 'activityLog' } );
452
480
  return res.sendError( error, 500 );
453
481
  }
@@ -510,7 +538,7 @@ async function activityLogData( requestData ) {
510
538
  };
511
539
  return activityLogData;
512
540
  } catch ( error ) {
513
- console.log( 'error =>', error );
541
+ // console.log( 'error =>', error );
514
542
  logger.error( { error: error, message: requestData, function: 'activityLogData' } );
515
543
  return res.sendError( error, 500 );
516
544
  }
@@ -1,6 +1,6 @@
1
1
  import * as taskService from '../service/task.service.js';
2
2
  import * as processedTaskService from '../service/processedTaskList.service.js';
3
- import { logger, download } from 'tango-app-api-middleware';
3
+ import { logger, download } from 'tango-app-api-middleware'; // getChecklistUsers
4
4
  import dayjs from 'dayjs';
5
5
  import mongoose from 'mongoose';
6
6
  // const ObjectId = mongoose.Types.ObjectId;
@@ -11,7 +11,7 @@ export const overallCards = async ( req, res ) => {
11
11
  let resultData = await overallCardsData( requestData );
12
12
  return res.sendSuccess( resultData );
13
13
  } catch ( error ) {
14
- console.log( 'error =>', error );
14
+ // console.log( 'error =>', error );
15
15
  logger.error( { error: error, function: 'overallCards' } );
16
16
  return res.sendError( error, 500 );
17
17
  }
@@ -42,7 +42,7 @@ async function overallCardsData( requestData ) {
42
42
  // resultData.card = cardData;
43
43
  return { cardData: cardData };
44
44
  } catch ( error ) {
45
- console.log( 'error =>', error );
45
+ // console.log( 'error =>', error );
46
46
  logger.error( { error: error, message: data, function: 'overallCardsData' } );
47
47
  }
48
48
  }
@@ -57,10 +57,16 @@ export const overallCardsV1 = async ( req, res ) => {
57
57
  let findQuery = [];
58
58
  let findAndQuery = [];
59
59
 
60
+ // Get User Based Checklist //
61
+ // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
62
+ // let getUserEmails = await getChecklistUsers( loginUser );
63
+ // End: Get User Based Checklist////
64
+
60
65
  findAndQuery.push(
61
66
  { date_iso: { $gte: fromDate, $lte: toDate } },
62
67
  { client_id: requestData.clientId },
63
- { store_id: { $in: requestData.storeId } },
68
+ // { store_id: { $in: requestData.storeId } },
69
+ { $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ] },
64
70
  );
65
71
 
66
72
  findQuery.push( { $match: { $and: findAndQuery } } );
@@ -102,7 +108,6 @@ export const overallCardsV1 = async ( req, res ) => {
102
108
  };
103
109
  export const taskTableV1 = async ( req, res ) => {
104
110
  try {
105
- console.log( 'req.body', req.body );
106
111
  let limit = parseInt( req.body.limit ) || 10;
107
112
  let offset = parseInt( req.body.offset - 1 ) || 0;
108
113
  let page = offset * limit;
@@ -184,7 +189,7 @@ export const taskTableV1 = async ( req, res ) => {
184
189
  { $sort: { createdAt: -1 } },
185
190
  );
186
191
  }
187
- console.log( 'page', page );
192
+ // console.log( 'page', page );
188
193
  query.push( {
189
194
  $facet: {
190
195
  data: [
@@ -215,7 +220,7 @@ export const taskTableV1 = async ( req, res ) => {
215
220
 
216
221
  return res.sendSuccess( { taskTableData: checkList[0].data, totalCount: checkList[0].count[0].totalCount } );
217
222
  } catch ( e ) {
218
- console.log( 'e', e );
223
+ // console.log( 'e', e );
219
224
  logger.error( 'checklist =>', e );
220
225
  return res.sendError( e, 500 );
221
226
  }
@@ -228,11 +233,17 @@ export const taskInfoTableV1 = async ( req, res ) => {
228
233
  let findQuery = [];
229
234
  let findAndQuery = [];
230
235
 
236
+ // Get User Based Checklist //
237
+ // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
238
+ // let getUserEmails = await getChecklistUsers( loginUser );
239
+ // End: Get User Based Checklist////
240
+
231
241
  findAndQuery.push(
232
242
  { date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
233
243
  { client_id: requestData.clientId },
234
- { store_id: { $in: requestData.storeId } },
235
244
  { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
245
+ // { store_id: { $in: requestData.storeId } },
246
+ { $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ] },
236
247
  );
237
248
  if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
238
249
  if ( requestData.checklistStatus == 'redo' ) {
@@ -253,7 +264,7 @@ export const taskInfoTableV1 = async ( req, res ) => {
253
264
  findQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
254
265
  query = { store: { $in: storeList } };
255
266
  } else {
256
- query = { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } };
267
+ query = { $or: [ { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } }, { userName: { $regex: requestData.searchValue.trim(), $options: 'i' } }, { userEmail: { $regex: requestData.searchValue.trim(), $options: 'i' } } ] };
257
268
  }
258
269
  findQuery.push( { $match: { $or: [ query ] } } );
259
270
  }
@@ -393,9 +404,24 @@ export const taskInfoTableV1 = async ( req, res ) => {
393
404
  taskInfoData[0].data[i].scheduleEndTime_iso = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
394
405
  }
395
406
  result.taskInfo = taskInfoData[0].data;
407
+ if ( req.body.export ) {
408
+ const exportResult = [];
409
+ for ( let task of result.taskInfo ) {
410
+ exportResult.push( {
411
+ 'Store': task?.storeName ||'--',
412
+ 'Store SPOC': task?.userEmail ||'--',
413
+ 'Due On': dayjs.utc( task?.scheduleEndTime_iso ).format( 'DD MMM, YYYY' ) || '--',
414
+ 'Submitted On': task?.submitTime_string || '--',
415
+ 'Assigned To': task?.storeCount ||'--',
416
+ 'status': task?.checklistStatus ||'--',
417
+ } );
418
+ }
419
+ await download( exportResult, res );
420
+ return;
421
+ }
396
422
  return res.sendSuccess( result );
397
423
  } catch ( error ) {
398
- console.log( 'error =>', error );
424
+ // console.log( 'error =>', error );
399
425
  logger.error( { error: error, message: req.query, function: 'taskInfo' } );
400
426
  return res.sendError( { error: error }, 500 );
401
427
  }
@@ -407,7 +433,7 @@ export const taskTable = async ( req, res ) => {
407
433
  let resultData = await taskTableData( requestData );
408
434
  return res.sendSuccess( resultData );
409
435
  } catch ( error ) {
410
- console.log( 'error =>', error );
436
+ // console.log( 'error =>', error );
411
437
  logger.error( { error: error, function: 'taskTable' } );
412
438
  return res.sendError( error, 500 );
413
439
  }
@@ -501,7 +527,7 @@ async function taskTableData( requestData ) {
501
527
  };
502
528
  return tableData;
503
529
  } catch ( error ) {
504
- console.log( 'error =>', error );
530
+ // console.log( 'error =>', error );
505
531
  logger.error( { error: error, message: requestData, function: 'taskTableData' } );
506
532
  return res.sendError( error, 500 );
507
533
  }
@@ -513,7 +539,7 @@ export const taskInfoTable = async ( req, res ) => {
513
539
  let resultData = await taskInfoTableData( requestData );
514
540
  return res.sendSuccess( resultData );
515
541
  } catch ( error ) {
516
- console.log( 'error =>', error );
542
+ // console.log( 'error =>', error );
517
543
  logger.error( { error: error, function: 'taskInfoTable' } );
518
544
  return res.sendError( error, 500 );
519
545
  }
@@ -647,7 +673,7 @@ async function taskInfoTableData( requestData ) {
647
673
  };
648
674
  return tableInfoData;
649
675
  } catch ( error ) {
650
- console.log( 'error =>', error );
676
+ // console.log( 'error =>', error );
651
677
  logger.error( { error: error, message: requestData, function: 'tableInfoData' } );
652
678
  return res.sendError( error, 500 );
653
679
  }
@@ -658,7 +684,7 @@ export const taskDropdownList = async ( req, res ) => {
658
684
  let resultData = await taskDropdownListData( requestData );
659
685
  return res.sendSuccess( resultData );
660
686
  } catch ( error ) {
661
- console.log( 'error =>', error );
687
+ // console.log( 'error =>', error );
662
688
  logger.error( { error: error, function: 'taskDropdownList' } );
663
689
  return res.sendError( error, 500 );
664
690
  }
@@ -711,7 +737,7 @@ async function taskDropdownListData( requestData ) {
711
737
  };
712
738
  return taskDropdownListData;
713
739
  } catch ( error ) {
714
- console.log( 'error =>', error );
740
+ // console.log( 'error =>', error );
715
741
  logger.error( { error: error, message: requestData, function: 'taskDropdownListData' } );
716
742
  return res.sendError( error, 500 );
717
743
  }
@@ -735,8 +761,9 @@ export const taskDropdownListV1 = async ( req, res ) => {
735
761
  checkListName: { $first: '$checkListName' },
736
762
  checkListType: { $first: '$checkListType' },
737
763
  createdByName: { $first: '$createdByName' },
738
- storeCount: { $first: '$storeCount' },
764
+ storeCount: { $sum: 1 },
739
765
  scheduleEndTimeISO: { $first: '$scheduleEndTimeISO' },
766
+ coverage: { $first: '$coverage' },
740
767
  // submitTime_string: { $first: '$submitTime_string' },
741
768
  },
742
769
  },
@@ -751,6 +778,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
751
778
  createdByName: 1,
752
779
  storeCount: 1,
753
780
  scheduleEndTimeISO: 1,
781
+ coverage: 1,
754
782
  // submitTime_string: 1,
755
783
  },
756
784
  } );
@@ -770,7 +798,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
770
798
  result.taskDropdown = getChecklistData;
771
799
  return res.sendSuccess( result );
772
800
  } catch ( error ) {
773
- console.log( 'error =>', error );
801
+ // console.log( 'error =>', error );
774
802
  logger.error( { error: error, message: req.query, function: 'checklistDropdown' } );
775
803
  return res.sendError( { error: error }, 500 );
776
804
  }
@@ -878,7 +906,7 @@ export const taskDropdownListNew = async ( req, res ) => {
878
906
  result.taskDropdown = getChecklistData;
879
907
  return res.sendSuccess( result );
880
908
  } catch ( error ) {
881
- console.log( 'error =>', error );
909
+ // console.log( 'error =>', error );
882
910
  logger.error( { error: error, message: req.query, function: 'checklistDropdownV1' } );
883
911
  return res.sendError( { error: error }, 500 );
884
912
  }
@@ -889,7 +917,7 @@ export const taskInfoView = async ( req, res ) => {
889
917
  let resultData = await taskInfoViewData( requestData );
890
918
  return res.sendSuccess( resultData );
891
919
  } catch ( error ) {
892
- console.log( 'error =>', error );
920
+ // console.log( 'error =>', error );
893
921
  logger.error( { error: error, function: 'taskInfoView' } );
894
922
  return res.sendError( error, 500 );
895
923
  }
@@ -920,7 +948,7 @@ async function taskInfoViewData( requestData ) {
920
948
  };
921
949
  return taskInfoViewData;
922
950
  } catch ( error ) {
923
- console.log( 'error =>', error );
951
+ // console.log( 'error =>', error );
924
952
  logger.error( { error: error, message: requestData, function: 'taskInfoViewData' } );
925
953
  return res.sendError( error, 500 );
926
954
  }
@@ -935,7 +963,7 @@ export const taskDeleteV1 = async ( req, res ) => {
935
963
 
936
964
  const taskConfig = await taskService.findOne( { _id: new mongoose.Types.ObjectId( requestData.taskId ) }, { _id: 1 } );
937
965
  if ( !taskConfig ) {
938
- console.log( 'Task found:', taskConfig );
966
+ // console.log( 'Task found:', taskConfig );
939
967
  return res.sendError( 'Task not found', 404 );
940
968
  }
941
969
 
@@ -945,7 +973,7 @@ export const taskDeleteV1 = async ( req, res ) => {
945
973
  );
946
974
 
947
975
  if ( resultData ) {
948
- console.log( 'Update result:', resultData );
976
+ // console.log( 'Update result:', resultData );
949
977
  return res.sendSuccess( { message: 'Task deleted successfully' } );
950
978
  } else {
951
979
  return res.sendError( 'Something went wrong please try again', 500 );
@@ -966,6 +994,12 @@ export async function taskDetails( req, res ) {
966
994
  return res.sendError( 'clientId is required', 400 );
967
995
  }
968
996
 
997
+ let requestData = req.body;
998
+ // Get User Based Checklist //
999
+ // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
1000
+ // let getUserEmails = await getChecklistUsers( loginUser );
1001
+ // End: Get User Based Checklist////
1002
+
969
1003
  let toDate = new Date( req.body.toDate );
970
1004
  let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
971
1005
  toDate = new Date( toDate.getTime() - userTimezoneOffset );
@@ -990,23 +1024,34 @@ export async function taskDetails( req, res ) {
990
1024
  $match: {
991
1025
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
992
1026
  client_id: req.body.clientId,
993
- ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
994
1027
  ...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
1028
+ // store_id: { $in: req.body.storeId },
1029
+ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
995
1030
  },
996
1031
  },
997
1032
  { $sort: { date_iso: -1 } },
998
1033
  {
999
1034
  $group: {
1000
- _id: '$sourceCheckList_id',
1001
- checkListName: { $first: '$checkListName' },
1002
- createdByName: { $first: '$createdByName' },
1003
- publishDate: { $first: '$publishDate' },
1004
- priorityType: { $first: '$priorityType' },
1005
- storeCount: { $first: '$storeCount' },
1006
- submitCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
1007
- redoCount: { $sum: { $cond: [ { $and: [ { $eq: [ '$redoStatus', true ] }, { $ne: [ '$checklistStatus', 'submit' ] } ] }, 1, 0 ] } },
1008
- scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
1009
- checkListChar: { $first: { $toUpper: { $substr: [ '$createdByName', 0, 2 ] } } },
1035
+ '_id': '$sourceCheckList_id',
1036
+ 'checkListName': { $first: '$checkListName' },
1037
+ 'coverage': {
1038
+ '$first': {
1039
+ '$cond': {
1040
+ 'if': { '$gt': [ { '$ifNull': [ '$referenceCheckListId', '' ] }, '' ] },
1041
+ 'then': 'checklist',
1042
+ 'else': '$coverage',
1043
+ },
1044
+ },
1045
+ },
1046
+ 'publishDate': { $first: '$publishDate' },
1047
+ 'priorityType': { $first: '$priorityType' },
1048
+ 'createdByName': { $first: '$createdByName' },
1049
+ // storeCount: { $first: '$storeCount' },
1050
+ 'storeCount': { $sum: 1 },
1051
+ 'submitCount': { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
1052
+ 'redoCount': { $sum: { $cond: [ { $and: [ { $eq: [ '$redoStatus', true ] }, { $ne: [ '$checklistStatus', 'submit' ] } ] }, 1, 0 ] } },
1053
+ 'scheduleEndTime_iso': { $first: '$scheduleEndTime_iso' },
1054
+ 'checkListChar': { $first: { $toUpper: { $substr: [ '$createdByName', 0, 2 ] } } },
1010
1055
  },
1011
1056
  },
1012
1057
  ];
@@ -0,0 +1,77 @@
1
+ import Joi from 'joi';
2
+
3
+
4
+ export const aitaskvalidationSchema = Joi.object().keys( {
5
+ storeName: Joi.string().required(),
6
+ taskName: Joi.string().required(),
7
+ question: Joi.string().required(),
8
+ answerType: Joi.string().required(),
9
+ approver: Joi.string().required(),
10
+ creator: Joi.string().required(),
11
+ options: Joi.string().optional(),
12
+ scheduleDate: Joi.string().optional(),
13
+ scheduleEndTime: Joi.string().optional(),
14
+ } );
15
+ export const StoreHygienetaskSchema = Joi.object().keys( {
16
+ storeName: Joi.string().required(),
17
+ taskName: Joi.string().required(),
18
+ question: Joi.string().required(),
19
+ answerType: Joi.string().required(),
20
+ options: Joi.string().optional(),
21
+ scheduleDate: Joi.string().optional(),
22
+ scheduleEndTime: Joi.string().optional(),
23
+ referenceImage: Joi.array().required(),
24
+ count: Joi.number().required(),
25
+ } );
26
+
27
+
28
+ export const eyeTesttaskSchema = Joi.object().keys( {
29
+ storeName: Joi.string().required(),
30
+ taskName: Joi.string().required(),
31
+ question: Joi.string().required(),
32
+ answerType: Joi.string().required(),
33
+ scheduleDate: Joi.string().required(),
34
+ scheduleEndTime: Joi.string().required(),
35
+ referenceImage: Joi.any().optional(),
36
+ } );
37
+ export const commonAiTaskSchema = Joi.object().keys( {
38
+ storeName: Joi.string().required(),
39
+ taskName: Joi.string().required(),
40
+ question: Joi.string().required(),
41
+ answerType: Joi.string().required(),
42
+ options: Joi.string().optional(),
43
+ scheduleDate: Joi.string().optional(),
44
+ scheduleEndTime: Joi.string().optional(),
45
+ referenceImage: Joi.array().required(),
46
+ } );
47
+ const questionSchema = Joi.object( {
48
+ question: Joi.string().required(),
49
+ answerType: Joi.string().required(),
50
+ options: Joi.array().items().optional(),
51
+ } );
52
+ export const taskcreationSchema = Joi.object().keys( {
53
+ storeName: Joi.string().required(),
54
+ taskName: Joi.string().required(),
55
+ user: Joi.string().required(),
56
+ questions: Joi.array().items( questionSchema ).required(),
57
+ scheduleDate: Joi.string().optional(),
58
+ scheduleEndTime: Joi.string().optional(),
59
+ approver: Joi.string().required(),
60
+ creator: Joi.string().required(),
61
+ } );
62
+
63
+ export const commonAiTaskvalidation = {
64
+ body: commonAiTaskSchema,
65
+ };
66
+ export const taskcreationvalidation = {
67
+ body: taskcreationSchema,
68
+ };
69
+ export const aitaskvalidation = {
70
+ body: aitaskvalidationSchema,
71
+ };
72
+ export const StoreHygienetaskvalidation = {
73
+ body: StoreHygienetaskSchema,
74
+ };
75
+ export const eyeTesttaskvalidation = {
76
+ body: eyeTesttaskSchema,
77
+ };
@@ -1,8 +1,8 @@
1
1
 
2
2
  import * as taskController from '../controllers/task.controller.js';
3
- import { isAllowedSessionHandler, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
3
+ import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient, isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
4
4
  import express from 'express';
5
-
5
+ import { aitaskvalidation, StoreHygienetaskvalidation, eyeTesttaskvalidation, commonAiTaskvalidation, taskcreationvalidation } from '../dtos/task.dto.js';
6
6
  export const taskRouter = express.Router();
7
7
 
8
8
  taskRouter
@@ -10,7 +10,7 @@ taskRouter
10
10
  .post( '/delete/:taskIds', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.deleteTask )
11
11
  .get( '/details', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskController.taskDetails )
12
12
  .get( '/userDetails', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskController.userDetails )
13
- .post( '/upload', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.validateUser )
13
+ .post( '/upload', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.validateUserv1 )
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
16
  .post( '/reinitiate', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
@@ -25,6 +25,17 @@ taskRouter
25
25
  .get( '/task-list', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ ] } ] } ), taskController.taskList )
26
26
  .put( '/publish', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.updatePublish )
27
27
  .get( '/duplicateTask/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.duplicateChecklist )
28
- .get( '/teamMigrations', taskController.teamMigrations );
28
+ .get( '/teamMigrations', taskController.teamMigrations )
29
+ .get( '/clusterMigrations', taskController.clusterMigrations )
30
+ .post( '/createaiChecklist', isAllowedInternalAPIHandler, taskController.createAiChecklist )
31
+ .post( '/createaiTask', isAllowedInternalAPIHandler, taskController.createAiTask )
32
+ .post( '/assign', isAllowedSessionHandler, taskController.taskAssign )
33
+ .post( '/createaiTask', isAllowedInternalAPIHandler, validate( aitaskvalidation ), taskController.createAiTask )
34
+ .post( '/StoreHygienetask', isAllowedInternalAPIHandler, validate( StoreHygienetaskvalidation ), taskController.StoreHygienetask )
35
+ .post( '/eyeTesttask', isAllowedInternalAPIHandler, validate( eyeTesttaskvalidation ), taskController.eyeTesttask )
36
+ .post( '/commonAiTask', isAllowedInternalAPIHandler, validate( commonAiTaskvalidation ), taskController.commonAiTask )
37
+ .post( '/updateAssign', isAllowedSessionHandler, taskController.updateAssign )
38
+ .post( '/taskcreation', isAllowedInternalAPIHandler, validate( taskcreationvalidation ), taskController.taskcreation )
39
+ .get( '/getcoustemer', taskController.customertrial );
29
40
 
30
41
 
@@ -8,14 +8,14 @@ import {
8
8
 
9
9
  taskDashboardRouter
10
10
  .post( '/overallcards', isAllowedSessionHandler, overallCards )
11
- .post( '/overallcardsV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), overallCardsV1 )
12
11
  .post( '/taskTable', isAllowedSessionHandler, taskTable )
13
12
  .post( '/taskTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskTableV1 )
14
13
  .post( '/taskInfoTable', isAllowedSessionHandler, taskInfoTable )
15
- .post( '/taskInfoTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskInfoTableV1 )
16
14
  .post( '/taskDropdownList', isAllowedSessionHandler, taskDropdownList )
17
- .post( '/taskDropdownListV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskDropdownListV1 )
18
15
  .post( '/taskDeleteV1', isAllowedSessionHandler, taskDeleteV1 )
19
- .post( '/taskDetails', isAllowedSessionHandler, taskDetails );
16
+ .post( '/taskDropdownListV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskDropdownListV1 )
17
+ .post( '/overallcardsV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), overallCardsV1 )
18
+ .post( '/taskDetails', isAllowedSessionHandler, taskDetails )
19
+ .post( '/taskInfoTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskInfoTableV1 );
20
20
 
21
21
  export default taskDashboardRouter;
@@ -0,0 +1,5 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const findOne = async ( query={}, field={} ) => {
4
+ return model.checklistconfigModel.findOne( query, field );
5
+ };
@@ -0,0 +1,31 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const find = async ( query={}, field={} ) => {
4
+ return model.checklistassignconfigModel.find( query, field );
5
+ };
6
+
7
+ export const findOne = async ( query={}, field={} ) => {
8
+ return model.checklistassignconfigModel.findOne( query, field );
9
+ };
10
+
11
+ export const create = async ( document = {} ) => {
12
+ return model.checklistassignconfigModel.create( document );
13
+ };
14
+
15
+ export const insertMany = async ( document = {} ) => {
16
+ return model.checklistassignconfigModel.insertMany( document );
17
+ };
18
+
19
+ export const deleteMany = async ( document = {} ) => {
20
+ return model.checklistassignconfigModel.deleteMany( document );
21
+ };
22
+
23
+ export const updateMany = async ( query = {}, record={} ) => {
24
+ return model.checklistassignconfigModel.updateMany( query, { $set: record } );
25
+ };
26
+
27
+ export const aggregate = async ( query = {} ) => {
28
+ return model.checklistassignconfigModel.aggregate( query );
29
+ };
30
+
31
+