tango-app-api-audit 3.5.26 → 3.5.27
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
|
@@ -1145,18 +1145,86 @@ export async function summaryList( req, res ) {
|
|
|
1145
1145
|
|
|
1146
1146
|
], count: 1 } );
|
|
1147
1147
|
} else if ( inputData.keyType === 'cluster' ) {
|
|
1148
|
-
|
|
1148
|
+
const clusterQuery =[
|
|
1149
|
+
{ $match: { 'Teamlead.email': { $in: inputData.RMList } } },
|
|
1150
|
+
{ $unwind: { path: '$stores', preserveNullAndEmptyArrays: true } },
|
|
1149
1151
|
{
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
trustScore: 0,
|
|
1152
|
+
$group: {
|
|
1153
|
+
_id: '$clusterName',
|
|
1154
|
+
clusterName: { $first: '$clusterName' },
|
|
1155
|
+
store: { $addToSet: '$stores.storeId' },
|
|
1156
|
+
|
|
1157
|
+
},
|
|
1157
1158
|
},
|
|
1159
|
+
{ $project: {
|
|
1160
|
+
RMName: inputData?.RMList[0],
|
|
1161
|
+
clusterName: 1,
|
|
1162
|
+
storesCount: { $size: '$store' },
|
|
1163
|
+
store: 1,
|
|
1164
|
+
} },
|
|
1165
|
+
];
|
|
1166
|
+
const getCluster = await aggregateClusters( clusterQuery );
|
|
1167
|
+
logger.info( { getCluster: getCluster } );
|
|
1168
|
+
if ( !getCluster || getCluster?.length == 0 ) {
|
|
1169
|
+
return res.sendError( 'No data', 400 );
|
|
1170
|
+
}
|
|
1171
|
+
const temp =[];
|
|
1172
|
+
for ( const [ i, cluster ] of getCluster.entries() ) {
|
|
1173
|
+
logger.info( { cluster: cluster } );
|
|
1174
|
+
temp.push( cluster );
|
|
1175
|
+
const getClusterQuery= {
|
|
1176
|
+
'size': 0,
|
|
1177
|
+
'query': {
|
|
1178
|
+
'bool': {
|
|
1179
|
+
'must': [
|
|
1180
|
+
{ 'terms': { 'storeId.keyword': cluster?.store } },
|
|
1181
|
+
{ 'term': { 'type.keyword': inputData?.type } },
|
|
1182
|
+
{
|
|
1183
|
+
'range': {
|
|
1184
|
+
'date': {
|
|
1185
|
+
'gte': inputData?.fromDate,
|
|
1186
|
+
'lte': inputData?.toDate,
|
|
1187
|
+
},
|
|
1188
|
+
},
|
|
1189
|
+
},
|
|
1158
1190
|
|
|
1159
|
-
|
|
1191
|
+
],
|
|
1192
|
+
},
|
|
1193
|
+
},
|
|
1194
|
+
'aggs': {
|
|
1195
|
+
'total_count': {
|
|
1196
|
+
'value_count': { 'field': '_id' },
|
|
1197
|
+
},
|
|
1198
|
+
'avg_complianceScore': {
|
|
1199
|
+
'avg': { 'field': 'ComplianceScore' },
|
|
1200
|
+
},
|
|
1201
|
+
'audited_trustScore': {
|
|
1202
|
+
'filter': { 'terms': { 'auditStatus.keyword': [ 'Audited', 'reAudited' ] } },
|
|
1203
|
+
'aggs': {
|
|
1204
|
+
'avg_trustScore': {
|
|
1205
|
+
'avg': { 'field': 'trustScore' },
|
|
1206
|
+
},
|
|
1207
|
+
'totalCount': {
|
|
1208
|
+
'value_count': { 'field': '_id' },
|
|
1209
|
+
},
|
|
1210
|
+
},
|
|
1211
|
+
},
|
|
1212
|
+
},
|
|
1213
|
+
};
|
|
1214
|
+
const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
|
|
1215
|
+
logger.info( { getResponse: getResponse } );
|
|
1216
|
+
if ( getResponse?.body?.aggregations ) {
|
|
1217
|
+
delete temp[i].store;
|
|
1218
|
+
delete temp[i]._id;
|
|
1219
|
+
temp[i].totalFiles = getResponse?.body?.aggregations?.total_count?.value || 0,
|
|
1220
|
+
temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
|
|
1221
|
+
temp[i].complianceScore = getResponse?.body?.aggregations?.avg_complianceScore?.value || 0;
|
|
1222
|
+
temp[i].trustScore =getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 'NA';
|
|
1223
|
+
logger.info( { getResponse: getResponse, ms: '........1' } );
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
return res.sendSuccess( { result: temp, count: getCluster?.length || 0 } );
|
|
1160
1228
|
} else {
|
|
1161
1229
|
let search ={
|
|
1162
1230
|
'must': filter,
|
|
@@ -1326,9 +1394,19 @@ export async function summaryList( req, res ) {
|
|
|
1326
1394
|
if ( element?._source?.userId&&element?._source?.userId!='' ) {
|
|
1327
1395
|
userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
|
|
1328
1396
|
}
|
|
1397
|
+
|
|
1398
|
+
let RMName = '';
|
|
1399
|
+
let clusterName='';
|
|
1400
|
+
if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
|
|
1401
|
+
const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
1402
|
+
RMName =( getCluster && getCluster.Teamlead?.length > 0 )? getCluster?.Teamlead?.[0]?.email : '';
|
|
1403
|
+
clusterName = getCluster?.clusterName;
|
|
1404
|
+
}
|
|
1329
1405
|
if ( element?._source?.type == 'physical' ) {
|
|
1330
1406
|
exportData.push( {
|
|
1331
1407
|
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1408
|
+
'RM Name': RMName,
|
|
1409
|
+
'Cluster Name': clusterName,
|
|
1332
1410
|
'Store Name': element?._source?.storeName,
|
|
1333
1411
|
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1334
1412
|
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
@@ -1346,6 +1424,8 @@ export async function summaryList( req, res ) {
|
|
|
1346
1424
|
} else {
|
|
1347
1425
|
exportData.push( {
|
|
1348
1426
|
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1427
|
+
'Cluster Name': clusterName,
|
|
1428
|
+
'Store Name': element?._source?.storeName,
|
|
1349
1429
|
'Store Name': element?._source?.storeName,
|
|
1350
1430
|
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1351
1431
|
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
@@ -5,7 +5,7 @@ export function aggregateClusters( query ) {
|
|
|
5
5
|
return clusterModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export function findClusters( query ) {
|
|
8
|
+
export function findClusters( query, field ) {
|
|
9
9
|
return clusterModel.find( query, field );
|
|
10
10
|
}
|
|
11
11
|
|