tango-app-api-trax 3.4.0-flag-11 → 3.4.1-activitylog-1

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.
@@ -27,7 +27,6 @@ dayjs.extend( timeZone );
27
27
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
28
28
  dayjs.extend( isSameOrBefore );
29
29
 
30
-
31
30
  export async function storeList( req, res ) {
32
31
  try {
33
32
  if ( !req.query?.date ) {
@@ -279,11 +278,10 @@ export async function startChecklist( req, res ) {
279
278
  createdBy: getBeforeChecklist[0]?.userName || '',
280
279
  coverage: getBeforeChecklist[0]?.coverage || '',
281
280
  logDetails: {},
281
+ userType: req.user.userType,
282
282
  };
283
283
  // let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
284
- console.log( 'inserttraxlogs', inserttraxlogs );
285
- let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
286
- console.log( 'insertOS', insertOS );
284
+ insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
287
285
  return res.sendSuccess( getchecklist );
288
286
  } else {
289
287
  return res.sendError( 'something went wrong please try again', 500 );
@@ -474,8 +472,7 @@ export async function startTask( req, res ) {
474
472
  };
475
473
  // let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
476
474
  console.log( 'inserttraxlogs', inserttraxlogs );
477
- let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
478
- console.log( 'insertOS', insertOS );
475
+ insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
479
476
  return res.sendSuccess( getUpdatedTask );
480
477
  } catch ( error ) {
481
478
  logger.error( { function: 'startTask', error, body: req.body } );
@@ -1797,6 +1794,7 @@ export async function submitChecklist( req, res ) {
1797
1794
  let flagCount = QuestionFlag( req, res );
1798
1795
  updateData.questionFlag = flagCount;
1799
1796
  updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
1797
+ updateData.deviceDetails = requestData?.deviceDetails || {};
1800
1798
  if ( requestData.submittype == 'draft' ) {
1801
1799
  logger.info( `v5 => Checklist Save => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
1802
1800
  updateData.questionAnswers = requestData.questionAnswers;
@@ -1848,7 +1846,7 @@ export async function submitChecklist( req, res ) {
1848
1846
  userName: getchecklist[0].userName || '',
1849
1847
  coverage: getchecklist[0].coverage || '',
1850
1848
  };
1851
- // console.log( 'logInsertData=>', logInsertData );s
1849
+ console.log( 'logInsertData=>', logInsertData );
1852
1850
  await checklistLogs.create( logInsertData );
1853
1851
  // let time = dayjs().format( 'HH:mm:ss' );
1854
1852
  // let [ hours, minutes ] = time.split( ':' ).map( Number );
@@ -1883,7 +1881,6 @@ export async function submitChecklist( req, res ) {
1883
1881
  // await detectionService.create( detectionData );
1884
1882
  if ( requestData.submittype == 'submit' ) {
1885
1883
  updateOpenSearch( req.user, requestData );
1886
-
1887
1884
  let openSearch = JSON.parse( process.env.OPENSEARCH );
1888
1885
  console.log( 'openSearch', openSearch );
1889
1886
  let inserttraxlogs = {
@@ -1902,13 +1899,12 @@ export async function submitChecklist( req, res ) {
1902
1899
  coverage: getchecklist[0].coverage,
1903
1900
  checkListType: getchecklist[0].checkListType,
1904
1901
  logDetails: {},
1902
+ userType: req.user.userType,
1905
1903
  };
1906
1904
  console.log( 'inserttraxlogs', inserttraxlogs );
1907
- let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
1908
- console.log( 'insertOS', insertOS );
1905
+ insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
1909
1906
  }
1910
1907
 
1911
-
1912
1908
  return res.sendSuccess( 'Checklist Updated Successfully' );
1913
1909
  } else {
1914
1910
  return res.sendError( 'something went wrong please try again', 500 );
@@ -2073,7 +2069,6 @@ export async function submitTask( req, res ) {
2073
2069
 
2074
2070
  if ( submittype == 'submit' ) {
2075
2071
  updateOpenSearchTask( user, requestData );
2076
-
2077
2072
  let openSearch = JSON.parse( process.env.OPENSEARCH );
2078
2073
  console.log( 'openSearch', openSearch );
2079
2074
  let inserttraxlogs = {
@@ -2092,10 +2087,10 @@ export async function submitTask( req, res ) {
2092
2087
  coverage: checklist.coverage,
2093
2088
  checkListType: checklist.checkListType,
2094
2089
  logDetails: {},
2090
+ userType: req.user.userType,
2095
2091
  };
2096
2092
  console.log( 'inserttraxlogs', inserttraxlogs );
2097
- let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
2098
- console.log( 'insertOS', insertOS );
2093
+ insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
2099
2094
  }
2100
2095
 
2101
2096
  return res.sendSuccess( 'Task Updated Successfully' );
@@ -2552,7 +2547,7 @@ export async function checklistv1( req, res ) {
2552
2547
  ...projectExtraConditions,
2553
2548
  client_id: { $ifNull: [ '$client_id', '' ] },
2554
2549
  coverage: { $ifNull: [ '$coverage', '' ] },
2555
- taskType: { $ifNull: [ '$type', '' ] },
2550
+ taskType: { $ifNull: [ '$planoType', '' ] },
2556
2551
  },
2557
2552
  },
2558
2553
  ];
@@ -2647,6 +2642,7 @@ export async function questionList( req, res ) {
2647
2642
  storeName: { $ifNull: [ '$storeName', '' ] },
2648
2643
  redoStatus: { $ifNull: [ '$redoStatus', false ] },
2649
2644
  rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
2645
+ rawVideoUpload: { $ifNull: [ '$rawVideoUpload', false ] },
2650
2646
  },
2651
2647
  } );
2652
2648
 
@@ -3336,7 +3332,7 @@ export const sendSignInOtpEmail = async ( emailVars ) => {
3336
3332
  const result = await sendEmailWithSES( emailVars.email, subject, html, attachments, ses.adminEmail );
3337
3333
  return result;
3338
3334
  } catch ( error ) {
3339
- logger.error( { error: error, function: 'sendSignInOtpEmail', body: req.body } );
3335
+ logger.error( { error: error, function: 'sendSignInOtpEmail', body: emailVars } );
3340
3336
  return error;
3341
3337
  }
3342
3338
  };
@@ -3487,8 +3483,8 @@ export async function clientConfig( req, res ) {
3487
3483
  try {
3488
3484
  let requestData = req.body;
3489
3485
  if ( requestData.clientId && requestData.clientId !='' ) {
3490
- let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1 } );
3491
- console.log( ' getClientData=>', getClientData );
3486
+ let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1, traxBlockMobileTimeUpdate: 1, traxSectionSave: 1 } );
3487
+ // console.log( ' getClientData=>', getClientData );
3492
3488
  if ( getClientData ) {
3493
3489
  return res.sendSuccess( getClientData );
3494
3490
  } else {
@@ -3498,7 +3494,6 @@ export async function clientConfig( req, res ) {
3498
3494
  return res.sendError( 'clientId is Required', 400 );
3499
3495
  }
3500
3496
  } catch ( e ) {
3501
- console.log( 'e =>', e );
3502
3497
  logger.error( { error: e, function: 'clientConfig' } );
3503
3498
  return res.sendError( e, 500 );
3504
3499
  }
@@ -3516,11 +3511,19 @@ export async function updatePlanoStatus( req, res ) {
3516
3511
  if ( !processCheckDetails ) {
3517
3512
  return res.sendError( 'No data found', 204 );
3518
3513
  }
3519
- processCheckDetails.checklistStatus = req.body.status;
3520
- processCheckDetails.save();
3514
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: processCheckDetails.storeName, $options: 'i' }, clientId: processCheckDetails.client_id }, { 'storeProfile.timeZone': 1 } );
3515
+ let currentDateTime;
3516
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
3517
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
3518
+ } else {
3519
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
3520
+ }
3521
+ let submitTimeString = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
3522
+ await processedchecklist.updateOne( { _id: req.body.id }, { checklistStatus: req.body.status, ...( req.body.status == 'inprogress' ) ? { startTime_string: submitTimeString } : { submitTime_string: submitTimeString } } );
3521
3523
  return res.sendSuccess( 'Status updated Successfully' );
3522
3524
  } catch ( e ) {
3523
3525
  logger.error( { error: e, function: 'updatePlanoStatus' } );
3524
3526
  return res.sendError( e, 500 );
3525
3527
  }
3526
3528
  }
3529
+
@@ -2463,6 +2463,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2463
2463
  'Store Id': element?.storeId,
2464
2464
  'Store Spoc Email': element?.storeSpocEmail,
2465
2465
  'Detections': element?.detections,
2466
+ 'Detection Status': element?.detectionStatus,
2466
2467
  } );
2467
2468
  } );
2468
2469
  return await download( exportdata, res );
@@ -2487,7 +2488,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2487
2488
  if ( reqestData.export ) {
2488
2489
  reqestData.limit = 10000;
2489
2490
  reqestData.offset = 0;
2490
- let LamdaURL = 'https://vpcejaftccr3jzqf5wrdkks7yy0krqix.lambda-url.ap-south-1.on.aws/';
2491
+ let LamdaURL = 'https://bnauly42yuztzrgtttodzt3bcm0oqrsi.lambda-url.ap-south-1.on.aws/';
2491
2492
  let resultData = await LamdaServiceCall( LamdaURL, reqestData );
2492
2493
  if ( resultData ) {
2493
2494
  if ( resultData.status_code == '200' ) {
@@ -2503,6 +2504,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2503
2504
  'Store Id': element?.storeId,
2504
2505
  // 'Store Spoc Email': element?.SpocEmail,
2505
2506
  'Detections': element?.detections,
2507
+ 'Detection Status': element?.detectionStatus,
2506
2508
  } );
2507
2509
  } );
2508
2510
  return await download( exportdata, res );
@@ -2515,7 +2517,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2515
2517
  }
2516
2518
  console.log( reqestData );
2517
2519
 
2518
- let LamdaURL = 'https://vpcejaftccr3jzqf5wrdkks7yy0krqix.lambda-url.ap-south-1.on.aws/';
2520
+ let LamdaURL = 'https://bnauly42yuztzrgtttodzt3bcm0oqrsi.lambda-url.ap-south-1.on.aws/';
2519
2521
  let resultData = await LamdaServiceCall( LamdaURL, reqestData );
2520
2522
  // console.log( 'resultData =>', resultData );
2521
2523
  if ( resultData ) {
@@ -2665,7 +2667,7 @@ export const checklistDropdownV1 = async ( req, res ) => {
2665
2667
  $or: [
2666
2668
  { questionFlag: { $gte: 1 } },
2667
2669
  { timeFlag: { $gte: 1 } },
2668
- { checkListType: { $in: [ 'custom', 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } },
2670
+ { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum' ] } },
2669
2671
  ],
2670
2672
  },
2671
2673
  ] } },
@@ -3163,3 +3165,59 @@ export const flagTablesV2 = async ( req, res ) => {
3163
3165
  return res.sendError( { error: error }, 500 );
3164
3166
  }
3165
3167
  };
3168
+
3169
+ export const checklistCountByType = async ( req, res ) => {
3170
+ try {
3171
+ let { clientId, fromDate, toDate } = req.body;
3172
+
3173
+ fromDate = new Date( fromDate );
3174
+ toDate = new Date( toDate );
3175
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
3176
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
3177
+ toDate.setUTCHours( 23, 59, 59, 999 );
3178
+
3179
+ let findQuery = [
3180
+ {
3181
+ $match: {
3182
+ client_id: clientId,
3183
+ date_iso: { $gte: fromDate, $lte: toDate },
3184
+ },
3185
+ },
3186
+ {
3187
+ $group: {
3188
+ _id: '$checkListType',
3189
+ count: { $sum: 1 },
3190
+ },
3191
+ },
3192
+ {
3193
+ $group: {
3194
+ _id: null,
3195
+ aiChecklistCount: { $sum: { $cond: [ { $ne: [ '$_id', 'custom' ] }, '$count', 0 ] } },
3196
+ customChecklistCount: { $sum: { $cond: [ { $eq: [ '$_id', 'custom' ] }, '$count', 0 ] } },
3197
+ },
3198
+ },
3199
+ { $project: { _id: 0 } },
3200
+ ];
3201
+
3202
+ let [ result ] = await processedchecklistconfigService.aggregate( findQuery );
3203
+ result = result || { aiChecklistCount: 0, customChecklistCount: 0 };
3204
+ // result.customChecklistCount = 0;
3205
+ // result.aiChecklistCount = 0;
3206
+ let showCards = 'allCards';
3207
+ if ( result.customChecklistCount > 0 && result.aiChecklistCount > 0 ) {
3208
+ showCards = 'allCards';
3209
+ } else if ( result.customChecklistCount > 0 && result.aiChecklistCount <= 0 ) {
3210
+ showCards = 'customCards';
3211
+ } else if ( result.customChecklistCount <= 0 && result.aiChecklistCount > 0 ) {
3212
+ showCards = 'aiCards';
3213
+ }
3214
+ result.showCards = showCards;
3215
+ return res.sendSuccess( {
3216
+ ...result,
3217
+ } );
3218
+ } catch ( error ) {
3219
+ logger.error( { error, function: 'checklistCountByType' } );
3220
+ return res.sendError( { error }, 500 );
3221
+ }
3222
+ };
3223
+