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.
@@ -614,9 +614,7 @@ export const flagCardsV1 = async ( req, res ) => {
614
614
  const resultData = await LamdaServiceCall( lambdaURL, detectionPayload );
615
615
 
616
616
  if ( resultData && resultData.status_code === '200' ) {
617
- delete resultData.status_code;
618
- const detectionFlags = Object.values( resultData ).reduce( ( acc, val ) => acc + val, 0 );
619
- flagCards.detectionFlag.count = Math.round( detectionFlags );
617
+ flagCards.detectionFlag.count = resultData.totalDetection;
620
618
  flagCards.totalFlag += flagCards.detectionFlag.count;
621
619
  }
622
620
 
@@ -701,8 +699,12 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
701
699
  return { comparisonData: 0, ComparisonFlag: false };
702
700
  }
703
701
 
704
- let comparisonData = Math.abs( ( ( rangeOneVal - rangeTwoVal ) / rangeOneVal ) * 100 );
705
- comparisonData = comparisonData % 1 === 0 ? comparisonData.toFixed( 0 ) : comparisonData.toFixed( 2 );
702
+ let comparisonData = Math.abs( ( ( rangeOneVal - rangeTwoVal ) / rangeTwoVal ) * 100 );
703
+ if ( comparisonData === Infinity ) comparisonData = 0;
704
+ comparisonData = comparisonData % 1 === 0 ? comparisonData.toFixed( 0 ) : comparisonData.toFixed( 1 );
705
+
706
+ comparisonData = parseInt( comparisonData );
707
+
706
708
 
707
709
  const ComparisonFlag = rangeOneVal > rangeTwoVal;
708
710
 
@@ -712,17 +714,24 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
712
714
  const getDetectionCount = async ( fromDate, toDate ) => {
713
715
  const detectionPayload = {
714
716
  fromDate: dayjs( fromDate ).format( 'YYYY-MM-DD' ),
715
- toDate: dayjs( toDate ).format( 'YYYY-MM-DD' ),
717
+ toDate: dayjs( toDate ).startOf( 'day' ).format( 'YYYY-MM-DD' ),
716
718
  storeId: requestData.storeId,
717
719
  clientId: requestData.clientId,
718
720
  };
719
721
 
722
+ console.log( dayjs( fromDate ).format( 'YYYY-MM-DD' ), 'from date' );
723
+
724
+ console.log( dayjs( toDate ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' ), 'current' );
725
+
726
+ console.log( dayjs( toDate ).format( 'YYYY-MM-DD' ), 'previous' );
727
+
728
+ console.log( dayjs( toDate ).startOf( 'day' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' ), 'new start of' );
729
+
720
730
  const LamdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
721
731
  const resultData = await LamdaServiceCall( LamdaURL, detectionPayload );
722
732
 
723
733
  if ( resultData?.status_code === '200' ) {
724
- delete resultData.status_code;
725
- return Object.values( resultData ).reduce( ( acc, curr ) => acc + curr, 0 );
734
+ return resultData.totalDetection;
726
735
  }
727
736
  return 0;
728
737
  };
@@ -808,6 +817,7 @@ export const flagTablesV1 = async ( req, res ) => {
808
817
  checkListType: 1,
809
818
  scheduleRepeatedType: 1,
810
819
  store_id: 1,
820
+ aiStoreList: 1,
811
821
  },
812
822
  } );
813
823
 
@@ -818,7 +828,8 @@ export const flagTablesV1 = async ( req, res ) => {
818
828
  checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
819
829
  sourceCheckList_id: { $last: '$sourceCheckList_id' },
820
830
  checkListType: { $last: '$checkListType' },
821
- assignedStores: { $max: '$storeCount' },
831
+ storeCount: { $sum: 1 },
832
+ storeCountAi: { $max: '$storeCount' },
822
833
  flaggedStores: {
823
834
  $addToSet: {
824
835
  $cond: [
@@ -874,22 +885,33 @@ export const flagTablesV1 = async ( req, res ) => {
874
885
  // $cond: [ { $gt: [ '$questionCount', 0 ] }, 1, 0 ],
875
886
  // },
876
887
  },
888
+ aiStoreList: { $max: '$aiStoreList' },
889
+ submittedQuestionCount: {
890
+ $sum: {
891
+ $cond: [
892
+ { $eq: [ '$checklistStatus', 'submit' ] },
893
+ '$questionCount', // Sum this field if status is 'submit'
894
+ 0, // Otherwise, add 0
895
+ ],
896
+ },
897
+ },
877
898
  },
878
899
  } );
879
900
 
880
901
  findQuery.push( {
881
902
  $project: {
903
+ assignedStores: '$storeCount',
904
+ assignedStoresAi: '$storeCountAi',
882
905
  checkListName: 1,
883
906
  checkListChar: 1,
884
907
  sourceCheckList_id: 1,
885
908
  checkListType: 1,
886
909
  flagType: 1,
887
- assignedStores: 1,
888
910
  uniqueFlaggedStores: 1,
889
911
  flaggedStores: { $size: '$flaggedStores' },
890
912
  flagCount: 1,
891
913
  questionCount: 1,
892
- correctAnswers: { $subtract: [ '$questionCount', '$questionFlag' ] },
914
+ correctAnswers: { $subtract: [ '$submittedQuestionCount', '$questionFlag' ] },
893
915
  // customType: {
894
916
  // $cond: { if: { $gte: [ '$questionFlag', 1 ] }, then: 'question', else: {
895
917
  // $cond: { if: { $gte: [ '$timeFlag', 1 ] }, then: 'time', else: '' },
@@ -899,6 +921,7 @@ export const flagTablesV1 = async ( req, res ) => {
899
921
  customQuestionFlagCount: '$questionFlag',
900
922
  customTimeFlagCount: '$timeFlag',
901
923
  // correctAnswers: '$questionFlag',
924
+ aiStoreList: 1,
902
925
  },
903
926
  } );
904
927
 
@@ -910,6 +933,7 @@ export const flagTablesV1 = async ( req, res ) => {
910
933
  checkListType: 1,
911
934
  flagType: 1,
912
935
  assignedStores: 1,
936
+ assignedStoresAi: 1,
913
937
  flaggedStores: 1,
914
938
  flagCount: 1,
915
939
  uniqueFlaggedStores: 1,
@@ -925,6 +949,8 @@ export const flagTablesV1 = async ( req, res ) => {
925
949
  // customType: 1,
926
950
  customQuestionFlagCount: 1,
927
951
  customTimeFlagCount: 1,
952
+ aiStoreList: 1,
953
+
928
954
  },
929
955
  } );
930
956
 
@@ -967,7 +993,8 @@ export const flagTablesV1 = async ( req, res ) => {
967
993
  if ( getChecklistPerformanceData[index].checkListType !== 'custom' ) {
968
994
  getChecklistPerformanceData[index].flagCount = resultData?.[getChecklistPerformanceData[index]?.checkListType] || 0;
969
995
  getChecklistPerformanceData[index].flaggedStores = resultData?.[`${getChecklistPerformanceData[index]?.checkListType}_flaggedstores`] || 0;
970
- getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].flaggedStores / resultData?.[getChecklistPerformanceData[index]?.checkListType] ) * 100;
996
+ getChecklistPerformanceData[index].assignedStores = getChecklistPerformanceData[index]?.aiStoreList?.filter( ( element ) => requestData.storeId.includes( element ) )?.length || 0;
997
+ getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
971
998
  getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
972
999
  getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
973
1000
  }
@@ -2179,19 +2206,19 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
2179
2206
 
2180
2207
 
2181
2208
  if ( rangeOneData.length >0 && rangeTwoData.length >0 ) {
2182
- flagComparisonCards.totalAssignedStores.comparisonData = ( ( ( rangeOneData[0].totalAssignedStores - rangeTwoData[0].totalAssignedStores )/rangeOneData[0].totalAssignedStores )*100 ).toFixed( 2 );
2209
+ flagComparisonCards.totalAssignedStores.comparisonData = ( ( ( rangeOneData[0].totalAssignedStores - rangeTwoData[0].totalAssignedStores )/rangeOneData[0].totalAssignedStores )*100 ).toFixed( 1 );
2183
2210
  if ( flagComparisonCards.totalAssignedStores.comparisonData > 0 ) {
2184
2211
  flagComparisonCards.totalAssignedStores.ComparisonFlag = true;
2185
2212
  } else {
2186
2213
  flagComparisonCards.totalAssignedStores.ComparisonFlag = false;
2187
2214
  }
2188
- flagComparisonCards.flagIncidents.comparisonData = ( ( ( rangeOneData[0].flagIncidents - rangeTwoData[0].flagIncidents )/rangeOneData[0].flagIncidents )*100 ).toFixed( 2 );
2215
+ flagComparisonCards.flagIncidents.comparisonData = ( ( ( rangeOneData[0].flagIncidents - rangeTwoData[0].flagIncidents )/rangeOneData[0].flagIncidents )*100 ).toFixed( 1 );
2189
2216
  if ( flagComparisonCards.flagIncidents.comparisonData > 0 ) {
2190
2217
  flagComparisonCards.flagIncidents.ComparisonFlag = true;
2191
2218
  } else {
2192
2219
  flagComparisonCards.flagIncidents.ComparisonFlag = false;
2193
2220
  }
2194
- flagComparisonCards.complianceRate.comparisonData = ( ( ( rangeOneData[0].complianceRate - rangeTwoData[0].complianceRate )/rangeOneData[0].complianceRate )*100 ).toFixed( 2 );
2221
+ flagComparisonCards.complianceRate.comparisonData = ( ( ( rangeOneData[0].complianceRate - rangeTwoData[0].complianceRate )/rangeOneData[0].complianceRate )*100 ).toFixed( 1 );
2195
2222
  if ( flagComparisonCards.complianceRate.comparisonData > 0 ) {
2196
2223
  flagComparisonCards.complianceRate.ComparisonFlag = true;
2197
2224
  } else {
@@ -2417,7 +2444,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2417
2444
  'Date': element?.date,
2418
2445
  'Store Name': element?.storeName,
2419
2446
  'Store Id': element?.storeId,
2420
- 'Store Spoc Email': element?.SpocEmail,
2447
+ // 'Store Spoc Email': element?.SpocEmail,
2421
2448
  'Detections': element?.detections,
2422
2449
  } );
2423
2450
  } );
@@ -213,7 +213,7 @@ export const create = async ( req, res ) => {
213
213
  let section = inputBody.sections[i];
214
214
  section.questions.forEach( ( section ) => {
215
215
  if ( section.questionReferenceImage && section.questionReferenceImage !='' ) {
216
- let imgUrl = section.questionReferenceImage.split( '?' )[0];
216
+ let imgUrl = decodeURIComponent( section.questionReferenceImage.split( '?' )[0] );
217
217
  let url = imgUrl.split( '/' );
218
218
  url.splice( 0, 3 );
219
219
  section.questionReferenceImage = url.join( '/' );
@@ -221,7 +221,7 @@ export const create = async ( req, res ) => {
221
221
  // if (['image', 'descriptiveImage'].includes(section.answerType) ) {
222
222
  section.answers.forEach( ( answer ) => {
223
223
  if ( answer.referenceImage != '' ) {
224
- let imgUrl = answer.referenceImage.split( '?' )[0];
224
+ let imgUrl = decodeURIComponent( answer.referenceImage.split( '?' )[0] );
225
225
  let url = imgUrl.split( '/' );
226
226
  url.splice( 0, 3 );
227
227
  answer.referenceImage = url.join( '/' );
@@ -768,9 +768,15 @@ export const assignedUserDetails = async ( req, res ) => {
768
768
  let skip = limit * page;
769
769
 
770
770
  let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ) } } ];
771
-
772
- if ( req.query.search && req.query.search != '' ) {
773
- query.push( { $match: { storeName: { $regex: req.query.search, $options: 'i' } } } );
771
+ if ( req.query.search.trim() && req.query.search.trim() != '' ) {
772
+ let searchValue = req.query.search;
773
+ searchValue = searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
774
+ if ( searchValue.length > 1 ) {
775
+ query.push( { $addFields: { storeLower: { $toLower: '$storeName' } } } );
776
+ query.push( { $match: { storeLower: { $in: searchValue } } } );
777
+ } else {
778
+ query.push( { $match: { storeName: { $regex: req.query.search.trim(), $options: 'i' } } } );
779
+ }
774
780
  }
775
781
 
776
782
  let checklistCount = await assignedService.aggregate( query );
@@ -1275,10 +1281,16 @@ export const validateUser = async ( req, res ) => {
1275
1281
  }
1276
1282
 
1277
1283
  if ( !req.body?.addUser ) {
1278
- let userChunk =await chunkArray( users, 10 );
1284
+ if ( req.body.hasOwnProperty( 'delete' ) ) {
1285
+ let checkExists = await assignedService.findOne( { userEmail: req.body.assignedUsers[0].userEmail, storeName: req.body.assignedUsers[0].storeName } );
1286
+ if ( checkExists ) {
1287
+ return res.sendError( 'User already Exists', 400 );
1288
+ }
1289
+ }
1290
+ // let userChunk =await chunkArray( users, 10 );
1279
1291
 
1280
- await Promise.all( userChunk.map( async ( chunk ) => {
1281
- await processUser( chunk );
1292
+ await Promise.all( users.map( async ( chunk ) => {
1293
+ await processUser( [ chunk ] );
1282
1294
  } ) );
1283
1295
 
1284
1296
  if ( userEmail.length || storeId.length || domainExists.length ) {
@@ -1380,7 +1392,7 @@ export const validateUser = async ( req, res ) => {
1380
1392
  if ( req.body.hasOwnProperty( 'delete' ) ) {
1381
1393
  let checkExists = await assignedService.findOne( { userEmail: req.body.assignedUsers[0].userEmail, storeName: req.body.assignedUsers[0].storeName } );
1382
1394
  if ( checkExists ) {
1383
- return res.sendSuccess( 'User already Exists' );
1395
+ return res.sendError( 'User already Exists', 400 );
1384
1396
  }
1385
1397
  }
1386
1398
 
@@ -1391,7 +1403,7 @@ export const validateUser = async ( req, res ) => {
1391
1403
  }
1392
1404
  } catch ( e ) {
1393
1405
  logger.error( 'validateUser 2=>', e );
1394
- return res.sendSuccess( e );
1406
+ return res.sendError( e, 500 );
1395
1407
  }
1396
1408
  };
1397
1409