tango-app-api-audit 1.0.24 → 1.0.25
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
|
@@ -800,9 +800,10 @@ export async function summarySplit( req, res ) {
|
|
|
800
800
|
auditInprogress: 0,
|
|
801
801
|
reAuditInprogress: 0,
|
|
802
802
|
draft: 0,
|
|
803
|
-
|
|
803
|
+
assigned: 0,
|
|
804
804
|
auditCompleted: 0,
|
|
805
805
|
reAuditCompleted: 0,
|
|
806
|
+
completedCount: 0,
|
|
806
807
|
};
|
|
807
808
|
|
|
808
809
|
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
@@ -885,7 +886,6 @@ export async function summarySplit( req, res ) {
|
|
|
885
886
|
completedCount: 1,
|
|
886
887
|
reAuditCompleted: 1,
|
|
887
888
|
auditCompleted: 1,
|
|
888
|
-
completedCount: 1,
|
|
889
889
|
|
|
890
890
|
},
|
|
891
891
|
},
|
|
@@ -1043,10 +1043,19 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
1043
1043
|
try {
|
|
1044
1044
|
const inputData = req.body;
|
|
1045
1045
|
let temp = {
|
|
1046
|
+
installedStores: 0,
|
|
1047
|
+
auditStores: 0,
|
|
1048
|
+
inprogreseStores: 0,
|
|
1049
|
+
completedStores: 0,
|
|
1050
|
+
auditInprogress: 0,
|
|
1051
|
+
reAuditInprogress: 0,
|
|
1052
|
+
draft: 0,
|
|
1053
|
+
assigned: 0,
|
|
1054
|
+
notAssigned: 0,
|
|
1055
|
+
auditCompleted: 0,
|
|
1056
|
+
reAuditCompleted: 0,
|
|
1046
1057
|
|
|
1047
1058
|
};
|
|
1048
|
-
const limit = inputData.limit || 10;
|
|
1049
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
1050
1059
|
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
1051
1060
|
let filters =[
|
|
1052
1061
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
@@ -1056,8 +1065,27 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
1056
1065
|
if ( inputData.clientId.length > 0 ) {
|
|
1057
1066
|
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
1058
1067
|
}
|
|
1068
|
+
const storeQuery = inputData.clientId.length? { 'edge.firstFile': true, 'clientId': { $in: inputData. clientId } } : { 'edge.firstFile': true };
|
|
1069
|
+
temp.installedStores = await countDocumentsStore( storeQuery );
|
|
1070
|
+
const auditClientDataQuery =[
|
|
1071
|
+
{
|
|
1072
|
+
$match: {
|
|
1073
|
+
$and: filters,
|
|
1074
|
+
},
|
|
1059
1075
|
|
|
1060
|
-
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
$group: {
|
|
1079
|
+
_id: null,
|
|
1080
|
+
totalFilesCount: { $sum: '$totalFilesCount' },
|
|
1081
|
+
},
|
|
1082
|
+
},
|
|
1083
|
+
];
|
|
1084
|
+
const auditClientData = await aggregateAuditClientData( auditClientDataQuery );
|
|
1085
|
+
if ( auditClientData.length >0 ) {
|
|
1086
|
+
temp.auditStores = auditClientData[0].totalFilesCount;
|
|
1087
|
+
}
|
|
1088
|
+
const storeAuditQuery =[
|
|
1061
1089
|
{
|
|
1062
1090
|
$match: {
|
|
1063
1091
|
$and: filters,
|
|
@@ -1066,104 +1094,59 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
1066
1094
|
},
|
|
1067
1095
|
{
|
|
1068
1096
|
$project: {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1097
|
+
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
1098
|
+
auditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
|
|
1099
|
+
reAuditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
|
|
1100
|
+
draft: { $cond: [ { $eq: [ '$status', 'drafted' ] }, 1, 0 ] },
|
|
1101
|
+
assigned: { $cond: [ { $eq: [ '$status', 'drafted' ] }, 1, 0 ] },
|
|
1102
|
+
exceptNoAssigned: { $cond: [ { $in: [ '$status', [ 'skipped', 'not_assign' ] ] }, 1, 0 ] },
|
|
1103
|
+
auditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
|
|
1104
|
+
reAuditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
|
|
1077
1105
|
|
|
1078
1106
|
|
|
1079
1107
|
},
|
|
1080
1108
|
},
|
|
1081
1109
|
{
|
|
1082
|
-
$
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
},
|
|
1093
|
-
{
|
|
1094
|
-
$project: {
|
|
1095
|
-
userName: 1,
|
|
1096
|
-
userEmail: '$email',
|
|
1097
|
-
},
|
|
1098
|
-
},
|
|
1099
|
-
], as: 'user',
|
|
1100
|
-
},
|
|
1101
|
-
},
|
|
1102
|
-
{
|
|
1103
|
-
$unwind: {
|
|
1104
|
-
path: '$user',
|
|
1105
|
-
preserveNullAndEmptyArrays: true,
|
|
1110
|
+
$group: {
|
|
1111
|
+
_id: null,
|
|
1112
|
+
completedStores: { $sum: '$completedStores' },
|
|
1113
|
+
auditInprogress: { $sum: '$auditInprogress' },
|
|
1114
|
+
reAuditInprogress: { $sum: '$reAuditInprogress' },
|
|
1115
|
+
draft: { $sum: '$draft' },
|
|
1116
|
+
assigned: { $sum: '$assigned' },
|
|
1117
|
+
exceptNoAssigned: { $sum: '$exceptNoAssigned' },
|
|
1118
|
+
auditCompleted: { $sum: '$auditCompleted' },
|
|
1119
|
+
reAuditCompleted: { $sum: '$reAuditCompleted' },
|
|
1106
1120
|
},
|
|
1107
1121
|
},
|
|
1108
1122
|
{
|
|
1109
1123
|
$project: {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1124
|
+
completedStores: 1,
|
|
1125
|
+
inprogressStores: { $subtract: [ temp.auditStores, '$completedStores' ] },
|
|
1126
|
+
auditInprogress: 1,
|
|
1127
|
+
reAuditInprogress: 1,
|
|
1128
|
+
draft: 1,
|
|
1129
|
+
assigned: 1,
|
|
1130
|
+
exceptNoAssigned: { $subtract: [ temp.auditStores, '$exceptNoAssigned' ] },
|
|
1131
|
+
auditCompleted: 1,
|
|
1132
|
+
reAuditCompleted: 1,
|
|
1119
1133
|
},
|
|
1120
1134
|
},
|
|
1121
1135
|
];
|
|
1122
|
-
|
|
1123
|
-
if (
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1136
|
+
const storeAudit = await aggregateStoreAudit( storeAuditQuery );
|
|
1137
|
+
if ( storeAudit.length > 0 ) {
|
|
1138
|
+
temp.inprogreseStores= storeAudit[0].inprogreseStores;
|
|
1139
|
+
temp.completedStores = storeAudit[0].completedStores;
|
|
1140
|
+
temp.auditInprogress = storeAudit[0].auditInprogress;
|
|
1141
|
+
temp.reAuditInprogress = storeAudit[0].reAuditInprogress;
|
|
1142
|
+
temp.draft = storeAudit[0].draft;
|
|
1143
|
+
temp.assigned = storeAudit[0].assigned;
|
|
1144
|
+
temp.notAssigned = storeAudit[0].exceptNoAssigned;
|
|
1145
|
+
temp.auditCompleted = storeAudit[0].auditCompleted;
|
|
1146
|
+
temp.reAuditCompleted = storeAudit[0].reAuditCompleted;
|
|
1129
1147
|
}
|
|
1130
1148
|
|
|
1131
|
-
|
|
1132
|
-
if ( count.length == 0 ) {
|
|
1133
|
-
return res.sendError( 'No Data Found', 204 );
|
|
1134
|
-
}
|
|
1135
|
-
if ( !inputData.isExport ) {
|
|
1136
|
-
query.push( {
|
|
1137
|
-
$skip: offset,
|
|
1138
|
-
},
|
|
1139
|
-
{
|
|
1140
|
-
$limit: limit,
|
|
1141
|
-
} );
|
|
1142
|
-
} else {
|
|
1143
|
-
query.push( { $limit: 10000 } );
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
const result = await aggregateStoreAudit( query );
|
|
1147
|
-
if ( inputData.isExport ) {
|
|
1148
|
-
const exportdata = [];
|
|
1149
|
-
result.forEach( ( element ) => {
|
|
1150
|
-
exportdata.push( {
|
|
1151
|
-
'File Date': element.storeId,
|
|
1152
|
-
'Store Id': element.fileDtae,
|
|
1153
|
-
'Store Name': element.audittype,
|
|
1154
|
-
'User Name': element.beforeCount,
|
|
1155
|
-
'user Email': element.startTime,
|
|
1156
|
-
'Audit Type': element.userName,
|
|
1157
|
-
'Before Count': element.userEmail,
|
|
1158
|
-
'After Count': element.auditStatus,
|
|
1159
|
-
'Accuracy': element.Accuracy,
|
|
1160
|
-
'Status': element.status,
|
|
1161
|
-
} );
|
|
1162
|
-
} );
|
|
1163
|
-
await download( exportdata, res );
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
1149
|
+
return res.sendSuccess( { result: temp } );
|
|
1167
1150
|
} catch ( error ) {
|
|
1168
1151
|
const err = error.message || 'Internal Server Error';
|
|
1169
1152
|
logger.error( { error: error, message: req.body, function: 'summarySplit' } );
|
|
@@ -5,6 +5,10 @@ export function findOneStore( query, fields ) {
|
|
|
5
5
|
return storeModel.findOne( query, fields );
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export function countDocumentsStore( query ) {
|
|
9
|
+
return storeModel.countDocuments( query );
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export function aggregateStore( query, fields ) {
|
|
9
13
|
return storeModel.aggregate( query, fields );
|
|
10
14
|
}
|