tango-app-api-trax 1.0.0-alpha.98 → 1.0.0-task.118

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.
@@ -276,19 +276,14 @@ export const checklistPerformance = async ( req, res ) => {
276
276
  let findQuery = [];
277
277
  let findAndQuery = [];
278
278
  findAndQuery.push(
279
+ { checkListType: { $eq: 'custom' } },
280
+ { date_iso: { $gte: fromDate, $lte: toDate } },
279
281
  { client_id: requestData.clientId },
280
282
  { store_id: { $in: requestData.storeId } },
281
- { date_iso: { $gte: fromDate } },
282
- { date_iso: { $lte: toDate } },
283
- { checkListType: { $eq: 'custom' } },
284
283
  );
285
284
 
286
285
  findQuery.push( { $match: { $and: findAndQuery } } );
287
286
 
288
- // if ( requestData.searchValue && requestData.searchValue != '' ) {
289
- // findQuery.push( { $match: { $or: [ { checkListName: { $regex: requestData.searchValue, $options: 'i' } } ] } } );
290
- // }
291
-
292
287
  if ( requestData.searchValue && requestData.searchValue != '' ) {
293
288
  let checkListSearch = requestData.searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
294
289
  let query;
@@ -301,21 +296,21 @@ export const checklistPerformance = async ( req, res ) => {
301
296
  findQuery.push( { $match: { $or: [ query ] } } );
302
297
  }
303
298
 
304
- findQuery.push( {
305
- $project: {
306
- sourceCheckList_id: 1,
307
- checkListId: 1,
308
- checkListName: 1,
309
- storeCount: 1,
310
- createdBy: 1,
311
- createdByName: 1,
312
- checklistStatus: 1,
313
- timeFlag: 1,
314
- questionFlag: 1,
315
- checkListType: 1,
316
- scheduleRepeatedType: 1,
317
- },
318
- } );
299
+ // findQuery.push( {
300
+ // $project: {
301
+ // sourceCheckList_id: 1,
302
+ // checkListId: 1,
303
+ // checkListName: 1,
304
+ // storeCount: 1,
305
+ // createdBy: 1,
306
+ // createdByName: 1,
307
+ // checklistStatus: 1,
308
+ // timeFlag: 1,
309
+ // questionFlag: 1,
310
+ // checkListType: 1,
311
+ // scheduleRepeatedType: 1,
312
+ // },
313
+ // } );
319
314
 
320
315
  findQuery.push( {
321
316
  $group: {
@@ -355,20 +350,33 @@ export const checklistPerformance = async ( req, res ) => {
355
350
  },
356
351
  } );
357
352
 
358
- let getTotalCount = await processedchecklistService.aggregate( findQuery );
359
- if ( !getTotalCount.length ) {
360
- return res.sendError( { error: 'No Data Found' }, 204 );
361
- }
362
-
363
353
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
364
354
  findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
365
355
  } else {
366
356
  findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
367
357
  }
368
358
 
359
+ let limit = parseInt( requestData?.limit ) || 10;
360
+ let skip = limit * ( requestData?.offset ) || 0;
361
+
362
+ findQuery.push( {
363
+ $facet: {
364
+ data: [
365
+ { $skip: skip }, { $limit: limit },
366
+ ],
367
+ count: [
368
+ { $count: 'total' },
369
+ ],
370
+ },
371
+ } );
372
+ let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
373
+ if ( !getChecklistPerformanceData[0].data.length ) {
374
+ return res.sendError( 'no data found', 204 );
375
+ }
376
+
369
377
  if ( requestData.export ) {
370
378
  const exportdata = [];
371
- getTotalCount.forEach( ( element ) => {
379
+ getChecklistPerformanceData[0].data.forEach( ( element ) => {
372
380
  exportdata.push( {
373
381
  'Checklist Name': element.checkListName,
374
382
  'Scheduled': element.scheduleRepeatedType,
@@ -380,13 +388,8 @@ export const checklistPerformance = async ( req, res ) => {
380
388
  return await download( exportdata, res );
381
389
  }
382
390
 
383
- let limit = parseInt( requestData?.limit ) || 10;
384
- let skip = limit * ( requestData?.offset ) || 0;
385
- findQuery.push( { $skip: skip }, { $limit: limit } );
386
- let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
387
-
388
- result.totalCount = getTotalCount.length;
389
- result.checklistPerformance = getChecklistPerformanceData;
391
+ result.totalCount = getChecklistPerformanceData[0].count[0].total;
392
+ result.checklistPerformance = getChecklistPerformanceData[0].data;
390
393
  return res.sendSuccess( result );
391
394
  } catch ( error ) {
392
395
  console.log( 'error =>', error );
@@ -467,8 +470,10 @@ export const storePerformance = async ( req, res ) => {
467
470
  },
468
471
  },
469
472
  checkListType: { $last: '$checkListType' },
470
- questionFlag: { $sum: '$questionFlag' },
473
+ // questionFlag: { $sum: '$questionFlag' },
474
+ questionFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionFlag', 0 ] } },
471
475
  questionCount: { $sum: '$questionCount' },
476
+ submitQuestionCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] } },
472
477
  },
473
478
  } );
474
479
 
@@ -487,7 +492,7 @@ export const storePerformance = async ( req, res ) => {
487
492
  completion: {
488
493
  $round: [ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] }, 0 ],
489
494
  },
490
- correctAnswers: { $subtract: [ '$questionCount', '$questionFlag' ] },
495
+ correctAnswers: { $subtract: [ '$submitQuestionCount', '$questionFlag' ] },
491
496
  },
492
497
  } );
493
498
 
@@ -511,7 +516,6 @@ export const storePerformance = async ( req, res ) => {
511
516
  then: 0,
512
517
  else: {
513
518
  $round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
514
- // $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
515
519
  },
516
520
  },
517
521
  },
@@ -535,14 +539,13 @@ export const storePerformance = async ( req, res ) => {
535
539
  completion: 1,
536
540
  compliance: 1,
537
541
  performance: { $round: [ { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] }, 0 ] },
538
- // performance: { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] },
539
542
  },
540
543
  } );
541
544
 
542
- let getTotalCount = await processedchecklistService.aggregate( findQuery );
543
- if ( !getTotalCount.length ) {
544
- return res.sendError( { error: 'No Data Found' }, 204 );
545
- }
545
+ // let getTotalCount = await processedchecklistService.aggregate( findQuery );
546
+ // if ( !getTotalCount.length ) {
547
+ // return res.sendError( { error: 'No Data Found' }, 204 );
548
+ // }
546
549
 
547
550
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
548
551
  if ( requestData.sortColumnName == 'storeName' ) {
@@ -554,9 +557,29 @@ export const storePerformance = async ( req, res ) => {
554
557
  findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
555
558
  }
556
559
 
560
+ let limit = parseInt( requestData?.limit ) || 10;
561
+ let skip = limit * ( requestData?.offset ) || 0;
562
+ findQuery.push( {
563
+ $facet: {
564
+ data: [
565
+ { $skip: skip }, { $limit: limit },
566
+ ],
567
+ count: [
568
+ { $count: 'total' },
569
+ ],
570
+ },
571
+ },
572
+ );
573
+
574
+ let getStorePerformanceData = await processedchecklistService.aggregate( findQuery );
575
+ if ( !getStorePerformanceData[0].data.length ) {
576
+ return res.sendError( { error: 'No Data Found' }, 204 );
577
+ }
578
+
579
+
557
580
  if ( requestData.export ) {
558
581
  const exportdata = [];
559
- getTotalCount.forEach( ( element ) => {
582
+ getStorePerformanceData[0].data.forEach( ( element ) => {
560
583
  exportdata.push( {
561
584
  'Store Name': element.storeName,
562
585
  'Store Spoc': element.userEmail,
@@ -570,13 +593,8 @@ export const storePerformance = async ( req, res ) => {
570
593
  return await download( exportdata, res );
571
594
  }
572
595
 
573
- let limit = parseInt( requestData?.limit ) || 10;
574
- let skip = limit * ( requestData?.offset ) || 0;
575
- findQuery.push( { $skip: skip }, { $limit: limit } );
576
- let getStorePerformanceData = await processedchecklistService.aggregate( findQuery );
577
-
578
- result.totalCount = getTotalCount.length;
579
- result.storePerformance = getStorePerformanceData;
596
+ result.totalCount = getStorePerformanceData[0].count[0].total;
597
+ result.storePerformance = getStorePerformanceData[0].data;
580
598
  return res.sendSuccess( result );
581
599
  } catch ( error ) {
582
600
  console.log( 'error =>', error );
@@ -598,11 +616,10 @@ export const userPerformance = async ( req, res ) => {
598
616
  let findQuery = [];
599
617
  let findAndQuery = [];
600
618
  findAndQuery.push(
619
+ { date_iso: { $gte: fromDate, $lte: toDate } },
620
+ { checkListType: { $eq: 'custom' } },
601
621
  { client_id: requestData.clientId },
602
622
  { store_id: { $in: requestData.storeId } },
603
- { date_iso: { $gte: fromDate } },
604
- { date_iso: { $lte: toDate } },
605
- { checkListType: { $eq: 'custom' } },
606
623
  );
607
624
 
608
625
  findQuery.push( { $match: { $and: findAndQuery } } );
@@ -643,6 +660,7 @@ export const userPerformance = async ( req, res ) => {
643
660
  storeName: 1,
644
661
  userEmail: 1,
645
662
  userName: 1,
663
+ questionCount: 1,
646
664
  },
647
665
  } );
648
666
 
@@ -659,8 +677,10 @@ export const userPerformance = async ( req, res ) => {
659
677
  },
660
678
  },
661
679
  checkListType: { $last: '$checkListType' },
662
- questionFlag: { $sum: '$questionFlag' },
680
+ // questionFlag: { $sum: '$questionFlag' },
681
+ questionFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionFlag', 0 ] } },
663
682
  questionCount: { $sum: '$questionCount' },
683
+ submittedChecklistQuestionCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] } },
664
684
  },
665
685
  } );
666
686
 
@@ -679,7 +699,7 @@ export const userPerformance = async ( req, res ) => {
679
699
  $round: [ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] }, 0 ],
680
700
  // $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ],
681
701
  },
682
- correctAnswers: { $subtract: [ '$questionCount', '$questionFlag' ] },
702
+ correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
683
703
  },
684
704
  } );
685
705
 
@@ -729,10 +749,10 @@ export const userPerformance = async ( req, res ) => {
729
749
  },
730
750
  } );
731
751
 
732
- let getTotalCount = await processedchecklistService.aggregate( findQuery );
733
- if ( !getTotalCount.length ) {
734
- return res.sendError( { error: 'No Data Found' }, 204 );
735
- }
752
+ // let getTotalCount = await processedchecklistService.aggregate( findQuery );
753
+ // if ( !getTotalCount.length ) {
754
+ // return res.sendError( { error: 'No Data Found' }, 204 );
755
+ // }
736
756
 
737
757
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
738
758
  if ( requestData.sortColumnName == 'userName' ) {
@@ -746,11 +766,26 @@ export const userPerformance = async ( req, res ) => {
746
766
 
747
767
  let limit = parseInt( requestData?.limit ) || 10;
748
768
  let skip = limit * ( requestData?.offset ) || 0;
749
- findQuery.push( { $skip: skip }, { $limit: limit } );
769
+ findQuery.push( {
770
+ $facet: {
771
+ data: [
772
+ { $skip: skip }, { $limit: limit },
773
+ ],
774
+ count: [
775
+ { $count: 'total' },
776
+ ],
777
+ },
778
+ },
779
+ );
780
+
750
781
  let getUserPerformanceData = await processedchecklistService.aggregate( findQuery );
751
782
 
752
- result.totalCount = getTotalCount.length;
753
- result.userPerformance = getUserPerformanceData;
783
+ if ( !getUserPerformanceData[0].data.length ) {
784
+ return res.sendError( { error: 'No Data Found' }, 204 );
785
+ }
786
+
787
+ result.totalCount = getUserPerformanceData[0].count[0].total;
788
+ result.userPerformance = getUserPerformanceData[0].data;
754
789
  return res.sendSuccess( result );
755
790
  } catch ( error ) {
756
791
  console.log( 'error =>', error );
@@ -2067,25 +2102,24 @@ export const overallCardsV1 = async ( req, res ) => {
2067
2102
  let findUniqueQuery = [];
2068
2103
  let findAndQuery = [];
2069
2104
  findAndQuery.push(
2105
+ { checkListType: { $eq: 'custom' } },
2106
+ { date_iso: { $gte: fromDate, $lte: toDate } },
2070
2107
  { client_id: requestData.clientId },
2071
2108
  { store_id: { $in: requestData.storeId } },
2072
- { date_iso: { $gte: fromDate } },
2073
- { date_iso: { $lte: toDate } },
2074
- { checkListType: { $eq: 'custom' } },
2075
2109
  );
2076
2110
 
2077
2111
  findQuery.push( { $match: { $and: findAndQuery } } );
2078
2112
 
2079
- findQuery.push( {
2080
- $project: {
2081
- sourceCheckList_id: 1,
2082
- checkListId: 1,
2083
- checklistStatus: 1,
2084
- timeFlag: 1,
2085
- questionFlag: 1,
2086
- questionCount: 1,
2087
- },
2088
- } );
2113
+ // findQuery.push( {
2114
+ // $project: {
2115
+ // sourceCheckList_id: 1,
2116
+ // checkListId: 1,
2117
+ // checklistStatus: 1,
2118
+ // timeFlag: 1,
2119
+ // questionFlag: 1,
2120
+ // questionCount: 1,
2121
+ // },
2122
+ // } );
2089
2123
 
2090
2124
  findQuery.push( {
2091
2125
  $group: {
@@ -2104,6 +2138,12 @@ export const overallCardsV1 = async ( req, res ) => {
2104
2138
  statusCounts: {
2105
2139
  $push: { k: '$_id', v: '$count' },
2106
2140
  },
2141
+ submiitedQuestionCount: {
2142
+ $push: { k: '$_id', v: '$totalQuestionCount' },
2143
+ },
2144
+ flaggedQuestionCount: {
2145
+ $push: { k: '$_id', v: '$totalQuestionFlagCount' },
2146
+ },
2107
2147
  questionCountSum: { $sum: '$totalQuestionCount' },
2108
2148
  questionFlagCountSum: { $sum: '$totalQuestionFlagCount' },
2109
2149
  timeFlagSum: { $sum: '$totalTimeFlag' },
@@ -2112,6 +2152,8 @@ export const overallCardsV1 = async ( req, res ) => {
2112
2152
  findQuery.push( {
2113
2153
  $addFields: {
2114
2154
  statusCounts: { $arrayToObject: '$statusCounts' },
2155
+ submittedChecklistQuestionCount: { $arrayToObject: '$submiitedQuestionCount' },
2156
+ submittedChecklistFlagQuestionCount: { $arrayToObject: '$flaggedQuestionCount' },
2115
2157
  },
2116
2158
  } );
2117
2159
  findQuery.push( {
@@ -2121,6 +2163,8 @@ export const overallCardsV1 = async ( req, res ) => {
2121
2163
  questionFlagCountSum: 1,
2122
2164
  timeFlagSum: 1,
2123
2165
  statusCounts: 1,
2166
+ submittedChecklistQuestionCount: 1,
2167
+ submittedChecklistFlagQuestionCount: 1,
2124
2168
  },
2125
2169
  } );
2126
2170
  findQuery.push( {
@@ -2135,7 +2179,7 @@ export const overallCardsV1 = async ( req, res ) => {
2135
2179
  // completionScore: { $multiply: [ { $divide: [ '$statusCounts.submit', '$totalChecklist' ] }, 100 ] },
2136
2180
  questionFlagCount: '$questionFlagCountSum',
2137
2181
  questionCount: '$questionCountSum',
2138
- correctAnswers: { $subtract: [ '$questionCountSum', '$questionFlagCountSum' ] },
2182
+ correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount.submit', '$submittedChecklistFlagQuestionCount.submit' ] },
2139
2183
  },
2140
2184
  } );
2141
2185
  findQuery.push( {
@@ -2162,11 +2206,6 @@ export const overallCardsV1 = async ( req, res ) => {
2162
2206
  },
2163
2207
  } );
2164
2208
  console.log( 'overallCardsV1 Query Hit 1=>' );
2165
- let getOverallChecklistData = await processedchecklistService.aggregate( findQuery );
2166
- console.log( 'overallCardsV1 Query Output 1=>', getOverallChecklistData );
2167
- if ( !getOverallChecklistData.length ) {
2168
- return res.sendError( { error: 'No Data Found' }, 204 );
2169
- }
2170
2209
  findUniqueQuery.push( { $match: { $and: findAndQuery } } );
2171
2210
  findUniqueQuery.push( {
2172
2211
  $project: {
@@ -2181,12 +2220,12 @@ export const overallCardsV1 = async ( req, res ) => {
2181
2220
  findUniqueQuery.push( {
2182
2221
  $count: 'totalUniqueChecklist',
2183
2222
  } );
2184
- console.log( 'overallCardsV1 unique checklist Query Hit 2 =>' );
2185
- let getUniqueChecklistData = await processedchecklistService.aggregate( findUniqueQuery );
2186
- console.log( 'overallCardsV1 unique checklist output 2 =>', getUniqueChecklistData );
2187
- if ( !getUniqueChecklistData.length && !getOverallChecklistData.length ) {
2188
- return res.sendError( { error: 'No Data Found' }, 204 );
2189
- }
2223
+
2224
+ const [ getOverallChecklistData, getUniqueChecklistData ] = await Promise.all( [
2225
+ processedchecklistService.aggregate( findQuery ),
2226
+ processedchecklistService.aggregate( findUniqueQuery ),
2227
+ ] );
2228
+
2190
2229
 
2191
2230
  if ( getUniqueChecklistData.length && getUniqueChecklistData.length>0 ) {
2192
2231
  if ( getUniqueChecklistData[0].totalUniqueChecklist ) {
@@ -2325,25 +2364,24 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2325
2364
  let rangeOneFindQuery = [];
2326
2365
  let rangeOneFindAndQuery = [];
2327
2366
  rangeOneFindAndQuery.push(
2367
+ { checkListType: { $eq: 'custom' } },
2368
+ { date_iso: { $gte: rangeOneFromDate, $lte: rangeOneToDate } },
2328
2369
  { client_id: requestData.clientId },
2329
2370
  { store_id: { $in: requestData.storeId } },
2330
- { date_iso: { $gte: rangeOneFromDate } },
2331
- { date_iso: { $lte: rangeOneToDate } },
2332
- { checkListType: { $eq: 'custom' } },
2333
2371
  );
2334
2372
 
2335
2373
  rangeOneFindQuery.push( { $match: { $and: rangeOneFindAndQuery } } );
2336
- rangeOneFindQuery.push( {
2337
- $project: {
2338
- sourceCheckList_id: 1,
2339
- checkListId: 1,
2340
- checklistStatus: 1,
2341
- timeFlag: 1,
2342
- questionFlag: 1,
2343
- questionCount: 1,
2344
- checkListType: 1,
2345
- },
2346
- } );
2374
+ // rangeOneFindQuery.push( {
2375
+ // $project: {
2376
+ // sourceCheckList_id: 1,
2377
+ // checkListId: 1,
2378
+ // checklistStatus: 1,
2379
+ // timeFlag: 1,
2380
+ // questionFlag: 1,
2381
+ // questionCount: 1,
2382
+ // checkListType: 1,
2383
+ // },
2384
+ // } );
2347
2385
  rangeOneFindQuery.push( {
2348
2386
  $group: {
2349
2387
  _id: '',
@@ -2388,31 +2426,28 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2388
2426
  },
2389
2427
  },
2390
2428
  } );
2391
- let rangeOneData = await processedchecklistService.aggregate( rangeOneFindQuery );
2392
- console.log( 'rangeOneData =>', rangeOneData );
2393
2429
 
2394
2430
  let rangeTwoFindQuery = [];
2395
2431
  let rangeTwoFindAndQuery = [];
2396
2432
  rangeTwoFindAndQuery.push(
2433
+ { checkListType: { $eq: 'custom' } },
2434
+ { date_iso: { $gte: rangeTwoFromDate, $lte: rangeTwoToDate } },
2397
2435
  { client_id: requestData.clientId },
2398
2436
  { store_id: { $in: requestData.storeId } },
2399
- { date_iso: { $gte: rangeTwoFromDate } },
2400
- { date_iso: { $lte: rangeTwoToDate } },
2401
- { checkListType: { $eq: 'custom' } },
2402
2437
  );
2403
2438
 
2404
2439
  rangeTwoFindQuery.push( { $match: { $and: rangeTwoFindAndQuery } } );
2405
- rangeTwoFindQuery.push( {
2406
- $project: {
2407
- sourceCheckList_id: 1,
2408
- checkListId: 1,
2409
- checklistStatus: 1,
2410
- timeFlag: 1,
2411
- questionFlag: 1,
2412
- questionCount: 1,
2413
- checkListType: 1,
2414
- },
2415
- } );
2440
+ // rangeTwoFindQuery.push( {
2441
+ // $project: {
2442
+ // sourceCheckList_id: 1,
2443
+ // checkListId: 1,
2444
+ // checklistStatus: 1,
2445
+ // timeFlag: 1,
2446
+ // questionFlag: 1,
2447
+ // questionCount: 1,
2448
+ // checkListType: 1,
2449
+ // },
2450
+ // } );
2416
2451
  rangeTwoFindQuery.push( {
2417
2452
  $group: {
2418
2453
  _id: '',
@@ -2457,23 +2492,28 @@ export const overallComparisonCardsV1 = async ( req, res ) => {
2457
2492
  },
2458
2493
  },
2459
2494
  } );
2460
- let rangeTwoData = await processedchecklistService.aggregate( rangeTwoFindQuery );
2495
+ const [ rangeOneData, rangeTwoData ] = await Promise.all( [
2496
+ processedchecklistService.aggregate( rangeOneFindQuery ),
2497
+ processedchecklistService.aggregate( rangeTwoFindQuery ),
2498
+ ] );
2461
2499
  console.log( 'rangeTwoData =>', rangeTwoData );
2500
+ console.log( 'rangeOneData =>', rangeOneData );
2501
+
2462
2502
 
2463
2503
  if ( rangeOneData.length >0 && rangeTwoData.length >0 ) {
2464
- overallComparisonCards.flags.comparisonData = Math.round( ( ( ( rangeOneData[0].flaggedChecklist - rangeTwoData[0].flaggedChecklist )/rangeOneData[0].flaggedChecklist )*100 ) ); // .toFixed( 2 )
2504
+ overallComparisonCards.flags.comparisonData = Math.round( ( ( ( rangeOneData[0].flaggedChecklist - rangeTwoData[0].flaggedChecklist )/rangeTwoData[0].flaggedChecklist )*100 ) ); // .toFixed( 2 )
2465
2505
  if ( overallComparisonCards.flags.comparisonData > 0 ) {
2466
2506
  overallComparisonCards.flags.ComparisonFlag = true;
2467
2507
  } else {
2468
2508
  overallComparisonCards.flags.ComparisonFlag = false;
2469
2509
  }
2470
- overallComparisonCards.completionScore.comparisonData = Math.round( ( ( ( rangeOneData[0].completionScore - rangeTwoData[0].completionScore )/rangeOneData[0].completionScore )*100 ) ); // .toFixed( 2 )
2510
+ overallComparisonCards.completionScore.comparisonData = Math.round( ( ( ( rangeOneData[0].completionScore - rangeTwoData[0].completionScore )/rangeTwoData[0].completionScore )*100 ) ); // .toFixed( 2 )
2471
2511
  if ( overallComparisonCards.completionScore.comparisonData > 0 ) {
2472
2512
  overallComparisonCards.completionScore.ComparisonFlag = true;
2473
2513
  } else {
2474
2514
  overallComparisonCards.completionScore.ComparisonFlag = false;
2475
2515
  }
2476
- overallComparisonCards.complianceRate.comparisonData = Math.round( ( ( ( rangeOneData[0].questionCompletionScore - rangeTwoData[0].questionCompletionScore )/rangeOneData[0].questionCompletionScore )*100 ) ); // .toFixed( 2 )
2516
+ overallComparisonCards.complianceRate.comparisonData = Math.round( ( ( ( rangeOneData[0].questionCompletionScore - rangeTwoData[0].questionCompletionScore )/rangeTwoData[0].questionCompletionScore )*100 ) ); // .toFixed( 2 )
2477
2517
  if ( overallComparisonCards.complianceRate.comparisonData > 0 ) {
2478
2518
  overallComparisonCards.complianceRate.ComparisonFlag = true;
2479
2519
  } else {
@@ -2666,6 +2706,15 @@ export const infoCardsV1 = async ( req, res ) => {
2666
2706
  timeFlag: { $sum: '$timeFlag' },
2667
2707
  questionFlagCount: { $sum: '$questionFlag' },
2668
2708
  questionCount: { $sum: '$questionCount' },
2709
+ submittedQuestionCount: {
2710
+ $sum: {
2711
+ $cond: [
2712
+ { $eq: [ '$checklistStatus', 'submit' ] },
2713
+ '$questionCount', // Sum this field if status is 'submit'
2714
+ 0, // Otherwise, add 0
2715
+ ],
2716
+ },
2717
+ },
2669
2718
  },
2670
2719
  } );
2671
2720
  findQuery.push( {
@@ -2681,7 +2730,8 @@ export const infoCardsV1 = async ( req, res ) => {
2681
2730
  questionFlagCount: 1,
2682
2731
  questionCount: 1,
2683
2732
  timeFlag: 1,
2684
- correctAnswers: { $subtract: [ '$questionCount', '$questionFlagCount' ] },
2733
+ submittedQuestionCount: 1,
2734
+ correctAnswers: { $subtract: [ '$submittedQuestionCount', '$questionFlagCount' ] },
2685
2735
  },
2686
2736
  } );
2687
2737
  findQuery.push( {
@@ -2697,6 +2747,7 @@ export const infoCardsV1 = async ( req, res ) => {
2697
2747
  questionCount: 1,
2698
2748
  timeFlag: 1,
2699
2749
  correctAnswers: 1,
2750
+ submittedQuestionCount: 1,
2700
2751
  questionCompletionScore: {
2701
2752
  $cond: {
2702
2753
  if: { $eq: [ '$questionCount', 0 ] },
@@ -3089,31 +3140,31 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
3089
3140
  }
3090
3141
 
3091
3142
  if ( rangeOneData.length >0 && rangeTwoData.length >0 ) {
3092
- infoComparisonCards.totalInstances.comparisonData = Math.round( ( ( ( rangeOneData[0].totalChecklist - rangeTwoData[0].totalChecklist )/rangeOneData[0].totalChecklist )*100 ) ); // .toFixed( 2 )
3143
+ infoComparisonCards.totalInstances.comparisonData = Math.round( ( ( ( rangeOneData[0].totalChecklist - rangeTwoData[0].totalChecklist )/rangeTwoData[0].totalChecklist )*100 ) ); // .toFixed( 2 )
3093
3144
  if ( infoComparisonCards.totalInstances.comparisonData > 0 ) {
3094
3145
  infoComparisonCards.totalInstances.ComparisonFlag = true;
3095
3146
  } else {
3096
3147
  infoComparisonCards.totalInstances.ComparisonFlag = false;
3097
3148
  }
3098
- infoComparisonCards.completedInstances.comparisonData = Math.round( ( ( ( rangeOneData[0].submittedChecklist - rangeTwoData[0].submittedChecklist )/rangeOneData[0].submittedChecklist )*100 ) ); // .toFixed( 2 )
3149
+ infoComparisonCards.completedInstances.comparisonData = Math.round( ( ( ( rangeOneData[0].submittedChecklist - rangeTwoData[0].submittedChecklist )/rangeTwoData[0].submittedChecklist )*100 ) ); // .toFixed( 2 )
3099
3150
  if ( infoComparisonCards.completedInstances.comparisonData > 0 ) {
3100
3151
  infoComparisonCards.completedInstances.ComparisonFlag = true;
3101
3152
  } else {
3102
3153
  infoComparisonCards.completedInstances.ComparisonFlag = false;
3103
3154
  }
3104
- infoComparisonCards.flags.comparisonData = Math.round( ( ( ( rangeOneData[0].flaggedChecklist - rangeTwoData[0].flaggedChecklist )/rangeOneData[0].flaggedChecklist )*100 ) ); // .toFixed( 2 )
3155
+ infoComparisonCards.flags.comparisonData = Math.round( ( ( ( rangeOneData[0].flaggedChecklist - rangeTwoData[0].flaggedChecklist )/rangeTwoData[0].flaggedChecklist )*100 ) ); // .toFixed( 2 )
3105
3156
  if ( infoComparisonCards.flags.comparisonData > 0 ) {
3106
3157
  infoComparisonCards.flags.ComparisonFlag = true;
3107
3158
  } else {
3108
3159
  infoComparisonCards.flags.ComparisonFlag = false;
3109
3160
  }
3110
- infoComparisonCards.completionScore.comparisonData = Math.round( ( ( ( rangeOneData[0].questionCompletionScore - rangeTwoData[0].questionCompletionScore )/rangeOneData[0].questionCompletionScore )*100 ) ); // .toFixed( 2 )
3161
+ infoComparisonCards.completionScore.comparisonData = Math.round( ( ( ( rangeOneData[0].questionCompletionScore - rangeTwoData[0].questionCompletionScore )/rangeTwoData[0].questionCompletionScore )*100 ) ); // .toFixed( 2 )
3111
3162
  if ( infoComparisonCards.completionScore.comparisonData > 0 ) {
3112
3163
  infoComparisonCards.completionScore.ComparisonFlag = true;
3113
3164
  } else {
3114
3165
  infoComparisonCards.completionScore.ComparisonFlag = false;
3115
3166
  }
3116
- infoComparisonCards.complianceRate.comparisonData = Math.round( ( ( ( rangeOneData[0].completionScore - rangeTwoData[0].completionScore )/rangeOneData[0].completionScore )*100 ) ); // .toFixed( 2 )
3167
+ infoComparisonCards.complianceRate.comparisonData = Math.round( ( ( ( rangeOneData[0].completionScore - rangeTwoData[0].completionScore )/rangeTwoData[0].completionScore )*100 ) ); // .toFixed( 2 )
3117
3168
  if ( infoComparisonCards.complianceRate.comparisonData > 0 ) {
3118
3169
  infoComparisonCards.complianceRate.ComparisonFlag = true;
3119
3170
  } else {
@@ -3444,7 +3495,6 @@ export const checklistDropdown = async ( req, res ) => {
3444
3495
  findAndQuery.push(
3445
3496
  { client_id: requestData.clientId },
3446
3497
  { checkListType: 'custom' },
3447
- { isdeleted: false },
3448
3498
  );
3449
3499
  findQuery.push( { $match: { $and: findAndQuery } } );
3450
3500
  findQuery.push( {
@@ -18,6 +18,8 @@ export const validateDownloadInsertSchema = joi.object( {
18
18
  viewFlag: joi.boolean().optional().allow( '' ),
19
19
  downloadInsertFrom: joi.string().optional().allow( '' ),
20
20
  userId: joi.string().optional().allow( '' ),
21
+ answerType: joi.string().optional().allow( '' ),
22
+ searchValue: joi.string().optional().allow( '' ),
21
23
  } );
22
24
 
23
25
  export const validateDownloadInsertParams = {
@@ -25,7 +27,9 @@ export const validateDownloadInsertParams = {
25
27
  };
26
28
 
27
29
  export const validateDownloadListSchema = joi.object( {
28
- ...baseSchema,
30
+ clientId: joi.string().required(),
31
+ fromDate: joi.string().optional().allow( '' ),
32
+ toDate: joi.string().optional().allow( '' ),
29
33
  createdBy: joi.string().optional().allow( '' ),
30
34
  searchValue: joi.string().optional().allow( '' ),
31
35
  sortBy: joi.number().optional().allow( '' ),
@@ -7,11 +7,17 @@ export const mobileRouter = express.Router();
7
7
 
8
8
  mobileRouter
9
9
  .get( '/storeList', isAllowedSessionHandler, mobileController.storeList )
10
+ .get( '/storeListv1', isAllowedSessionHandler, mobileController.storeListv1 )
10
11
  .post( '/startCheckList', isAllowedSessionHandler, validate( startValidation ), mobileController.startChecklist )
12
+ .post( '/startTask', isAllowedSessionHandler, validate( startValidation ), mobileController.startTask )
11
13
  .post( '/submitCheckList', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidator, mobileController.sopMobilechecklistMultiSectionFormatter, mobileController.submitChecklist )
14
+ .post( '/submitTask', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobileTaskQuestionValidator, mobileController.sopMobileTaskMultiSectionFormatter, mobileController.submitTask )
12
15
  .get( '/dashboard', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboard )
16
+ .get( '/dashboardv1', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboardv1 )
13
17
  .get( '/checklist', isAllowedSessionHandler, validate( mobileChecklistValidation ), mobileController.checklist )
18
+ .get( '/checklistv1', isAllowedSessionHandler, validate( mobileChecklistValidation ), mobileController.checklistv1 )
14
19
  .get( '/checklistQuestionList', isAllowedSessionHandler, mobileController.questionList )
20
+ .get( '/taskQuestionList', isAllowedSessionHandler, mobileController.taskQuestionList )
15
21
  .post( '/uploadAnswerImage', isAllowedSessionHandler, mobileController.uploadAnswerImage )
16
22
  .get( '/appVersion', mobileController.appVersion )
17
23
  .post( '/appVersion', mobileController.updateappVersion )