tango-app-api-trax 3.3.1-beta-61 → 3.3.1-beta-63
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.
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.3.1-beta-
|
|
3
|
+
"version": "3.3.1-beta-63",
|
|
4
4
|
"description": "Trax",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -152,7 +152,7 @@ export async function storesList( req, res ) {
|
|
|
152
152
|
export const checklistDropdown = async ( req, res ) => {
|
|
153
153
|
try {
|
|
154
154
|
let requestData = req.body;
|
|
155
|
-
|
|
155
|
+
let fromDate = new Date( requestData.fromDate );
|
|
156
156
|
let toDate = new Date( requestData.toDate );
|
|
157
157
|
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
158
158
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
@@ -163,8 +163,8 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
163
163
|
let findAndQuery = [];
|
|
164
164
|
findAndQuery.push(
|
|
165
165
|
{ client_id: requestData.clientId },
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
{ date_iso: { $gte: fromDate } },
|
|
167
|
+
{ date_iso: { $lte: toDate } },
|
|
168
168
|
// { checkListType: { $eq: 'custom' } },
|
|
169
169
|
);
|
|
170
170
|
|
|
@@ -2086,9 +2086,9 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2086
2086
|
let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
2087
2087
|
item._id = getStoreDetails._id;
|
|
2088
2088
|
item.storeId = getStoreDetails.storeId;
|
|
2089
|
-
item.userName = storeUserDetails ? storeUserDetails?.userName :
|
|
2089
|
+
item.userName = storeUserDetails ? storeUserDetails?.userName : item.userName;
|
|
2090
2090
|
item.storeName = getStoreDetails.storeName;
|
|
2091
|
-
item.userEmail = storeUserDetails ? storeUserDetails?.email :
|
|
2091
|
+
item.userEmail = storeUserDetails ? storeUserDetails?.email : item.userEmail;
|
|
2092
2092
|
}
|
|
2093
2093
|
} );
|
|
2094
2094
|
} else {
|
|
@@ -3730,9 +3730,9 @@ export async function checklistAssign( req, res ) {
|
|
|
3730
3730
|
|
|
3731
3731
|
export async function updateAssign( req, res ) {
|
|
3732
3732
|
try {
|
|
3733
|
-
if ( !req.body.assignedList.length && !req.body.assignedGroup.length ) {
|
|
3734
|
-
|
|
3735
|
-
}
|
|
3733
|
+
// if ( !req.body.assignedList.length && !req.body.assignedGroup.length ) {
|
|
3734
|
+
// return res.sendError( 'No data found', 204 );
|
|
3735
|
+
// }
|
|
3736
3736
|
let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId, client_id: req.body.clientId } );
|
|
3737
3737
|
if ( !checklistDetails ) {
|
|
3738
3738
|
return res.sendError( 'No data found', 204 );
|
|
@@ -738,119 +738,91 @@ export const userPerformance = async ( req, res ) => {
|
|
|
738
738
|
userEmail: { $last: '$userEmail' },
|
|
739
739
|
checkListCount: { $sum: '$_id' },
|
|
740
740
|
timeFlag: { $sum: '$timeFlag' },
|
|
741
|
-
submittedChecklist: {
|
|
742
|
-
$sum: {
|
|
743
|
-
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
|
|
744
|
-
},
|
|
745
|
-
},
|
|
741
|
+
submittedChecklist: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
|
|
746
742
|
checkListType: { $last: '$checkListType' },
|
|
747
|
-
// questionFlag: { $sum: '$questionFlag' },
|
|
748
743
|
questionFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionFlag', 0 ] } },
|
|
749
744
|
questionCount: { $sum: '$questionCount' },
|
|
750
|
-
submittedChecklistQuestionCount: {
|
|
745
|
+
submittedChecklistQuestionCount: {
|
|
746
|
+
$sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] },
|
|
747
|
+
},
|
|
751
748
|
},
|
|
752
749
|
} );
|
|
753
750
|
|
|
751
|
+
|
|
754
752
|
findQuery.push( {
|
|
755
|
-
$
|
|
753
|
+
$addFields: {
|
|
756
754
|
userName: '$_id',
|
|
757
|
-
userEmail: 1,
|
|
758
|
-
checkListCount: { $sum: '$totalChecklist' },
|
|
759
755
|
flaggedCount: { $add: [ '$timeFlag', '$questionFlag' ] },
|
|
760
|
-
|
|
761
|
-
timeFlag: 1,
|
|
762
|
-
checkListType: 1,
|
|
763
|
-
questionCount: 1,
|
|
764
|
-
questionFlag: 1,
|
|
756
|
+
correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
|
|
765
757
|
completion: {
|
|
766
|
-
$round: [
|
|
767
|
-
|
|
758
|
+
$round: [
|
|
759
|
+
{ $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] },
|
|
760
|
+
0,
|
|
761
|
+
],
|
|
768
762
|
},
|
|
769
|
-
correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
|
|
770
763
|
},
|
|
771
764
|
} );
|
|
772
765
|
|
|
766
|
+
|
|
773
767
|
findQuery.push( {
|
|
774
|
-
$
|
|
775
|
-
userName: 1,
|
|
776
|
-
userEmail: 1,
|
|
777
|
-
checkListCount: 1,
|
|
778
|
-
flaggedCount: 1,
|
|
779
|
-
submittedChecklist: 1,
|
|
780
|
-
checkListType: 1,
|
|
781
|
-
questionCount: 1,
|
|
782
|
-
questionFlag: 1,
|
|
783
|
-
timeFlag: 1,
|
|
784
|
-
completion: 1,
|
|
785
|
-
compliance: 1,
|
|
768
|
+
$addFields: {
|
|
786
769
|
compliance: {
|
|
787
770
|
$cond: {
|
|
788
771
|
if: { $eq: [ '$questionCount', 0 ] },
|
|
789
772
|
then: 0,
|
|
790
773
|
else: {
|
|
791
774
|
$round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
|
|
792
|
-
// $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
|
|
793
775
|
},
|
|
794
776
|
},
|
|
795
777
|
},
|
|
778
|
+
lowercaseUserName: { $toLower: '$userName' },
|
|
796
779
|
},
|
|
797
780
|
} );
|
|
798
781
|
|
|
799
782
|
findQuery.push( {
|
|
800
|
-
$
|
|
801
|
-
userName: 1,
|
|
802
|
-
lowercaseUserName: { $toLower: '$userName' },
|
|
803
|
-
userEmail: 1,
|
|
804
|
-
checkListCount: 1,
|
|
805
|
-
flaggedCount: 1,
|
|
806
|
-
submittedChecklist: 1,
|
|
807
|
-
checkListType: 1,
|
|
808
|
-
questionCount: 1,
|
|
809
|
-
questionFlag: 1,
|
|
810
|
-
timeFlag: 1,
|
|
811
|
-
correctAnswers: 1,
|
|
812
|
-
completion: 1,
|
|
813
|
-
compliance: 1,
|
|
783
|
+
$addFields: {
|
|
814
784
|
performance: { $round: [ { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] }, 0 ] },
|
|
815
|
-
// performance: { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] },
|
|
816
785
|
},
|
|
817
786
|
} );
|
|
818
787
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
825
|
-
if ( requestData.sortColumnName == 'userName' ) {
|
|
826
|
-
findQuery.push( { $sort: { ['lowercaseUserName']: requestData.sortBy } } );
|
|
827
|
-
} else {
|
|
828
|
-
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
829
|
-
}
|
|
788
|
+
if ( requestData.sortColumnName && requestData.sortBy ) {
|
|
789
|
+
const sortField =
|
|
790
|
+
requestData.sortColumnName === 'userName' ? 'lowercaseUserName' : requestData.sortColumnName;
|
|
791
|
+
findQuery.push( { $sort: { [sortField]: requestData.sortBy } } );
|
|
830
792
|
} else {
|
|
831
|
-
findQuery.push( { $sort: {
|
|
793
|
+
findQuery.push( { $sort: { userName: -1 } } );
|
|
832
794
|
}
|
|
833
795
|
|
|
834
796
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
835
|
-
let skip = limit * ( requestData?.offset
|
|
797
|
+
let skip = limit * ( requestData?.offset || 0 );
|
|
836
798
|
findQuery.push( {
|
|
837
799
|
$facet: {
|
|
838
|
-
data: [
|
|
839
|
-
|
|
840
|
-
],
|
|
841
|
-
count: [
|
|
842
|
-
{ $count: 'total' },
|
|
843
|
-
],
|
|
800
|
+
data: [ { $skip: skip }, { $limit: limit } ],
|
|
801
|
+
count: [ { $count: 'total' } ],
|
|
844
802
|
},
|
|
845
|
-
}
|
|
846
|
-
|
|
803
|
+
} );
|
|
804
|
+
|
|
847
805
|
|
|
848
806
|
let getUserPerformanceData = await processedchecklistService.aggregate( findQuery );
|
|
849
807
|
|
|
850
808
|
if ( !getUserPerformanceData[0].data.length ) {
|
|
851
809
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
852
810
|
}
|
|
853
|
-
|
|
811
|
+
if ( requestData.export ) {
|
|
812
|
+
const exportdata = [];
|
|
813
|
+
getUserPerformanceData[0].data.forEach( ( element ) => {
|
|
814
|
+
exportdata.push( {
|
|
815
|
+
'User Name': element.userName || '--',
|
|
816
|
+
'Email': element.userEmail || '--',
|
|
817
|
+
'Checklist Assigned': element.checkListCount || '--',
|
|
818
|
+
'Flags': element.flaggedCount || '--',
|
|
819
|
+
'Completion %': element.completion || '--',
|
|
820
|
+
'Compliance %': element.compliance || '--',
|
|
821
|
+
'Performance %': element.performance || '--',
|
|
822
|
+
} );
|
|
823
|
+
} );
|
|
824
|
+
return await download( exportdata, res );
|
|
825
|
+
}
|
|
854
826
|
result.totalCount = getUserPerformanceData[0].count[0].total;
|
|
855
827
|
result.userPerformance = getUserPerformanceData[0].data;
|
|
856
828
|
return res.sendSuccess( result );
|
|
@@ -1358,6 +1330,42 @@ export const checklistInfo = async ( req, res ) => {
|
|
|
1358
1330
|
getChecklistPerformanceData[i].date_string = dayjs( getChecklistPerformanceData[i].date_string ).format( 'DD MMM YYYY' );
|
|
1359
1331
|
}
|
|
1360
1332
|
result.checklistInfo = getChecklistPerformanceData;
|
|
1333
|
+
if ( requestData.export ) {
|
|
1334
|
+
const exportdata = [];
|
|
1335
|
+
result.checklistInfo.forEach( ( element ) => {
|
|
1336
|
+
if ( requestData.groupByType==='Checklist' ) {
|
|
1337
|
+
exportdata.push( {
|
|
1338
|
+
'Date': element.date_string || '--',
|
|
1339
|
+
'Store Name': element.storeName || '--',
|
|
1340
|
+
'Checklist Owner': element.userName || '--',
|
|
1341
|
+
'Submitted By': element.userName || '--',
|
|
1342
|
+
'Status': element.checklistStatus || '--',
|
|
1343
|
+
'Submitted On': element.submitTime_string || '--',
|
|
1344
|
+
'Flags': element.flaggedChecklist || '--',
|
|
1345
|
+
} );
|
|
1346
|
+
} else if ( requestData.groupByType==='Store' ) {
|
|
1347
|
+
exportdata.push( {
|
|
1348
|
+
'CheckList Name': element.checkListName || '--',
|
|
1349
|
+
'Checklist Owner': element.userName || '--',
|
|
1350
|
+
'Submitted By': element.userName || '--',
|
|
1351
|
+
'Status': element.checklistStatus || '--',
|
|
1352
|
+
'Submitted On': element.submitTime_string || '--',
|
|
1353
|
+
'Flags': element.flaggedChecklist || '--',
|
|
1354
|
+
} );
|
|
1355
|
+
} else {
|
|
1356
|
+
exportdata.push( {
|
|
1357
|
+
'Date': element.date_string || '--',
|
|
1358
|
+
'CheckList Name': element.checkListName || '--',
|
|
1359
|
+
'Store Name': element.storeName || '--',
|
|
1360
|
+
'Checklist Owner': element.userName || '--',
|
|
1361
|
+
'Status': element.checklistStatus || '--',
|
|
1362
|
+
'Submitted On': element.submitTime_string || '--',
|
|
1363
|
+
'Flags': element.flaggedChecklist || '--',
|
|
1364
|
+
} );
|
|
1365
|
+
}
|
|
1366
|
+
} );
|
|
1367
|
+
return await download( exportdata, res );
|
|
1368
|
+
}
|
|
1361
1369
|
return res.sendSuccess( result );
|
|
1362
1370
|
} catch ( error ) {
|
|
1363
1371
|
console.log( 'error =>', error );
|