tango-app-api-audit 3.5.46 → 3.5.48
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
|
import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray, getOpenSearchCount, insertWithId } from 'tango-app-api-middleware';
|
|
2
|
-
import { findOneUser, findUser } from '../service/user.service.js';
|
|
2
|
+
import { aggregateUser, findOneUser, findUser } from '../service/user.service.js';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import utc from 'dayjs/plugin/utc.js';
|
|
6
6
|
import timezone from 'dayjs/plugin/timezone.js';
|
|
7
7
|
import 'dayjs/locale/en.js';
|
|
8
|
-
import { findOneEyeTestConfig, updateOneEyeTestConfig } from '../service/eyeTestConfiguration.service.js';
|
|
8
|
+
import { aggregateEyeTestConfig, findOneEyeTestConfig, updateOneEyeTestConfig } from '../service/eyeTestConfiguration.service.js';
|
|
9
9
|
import { ObjectId } from 'mongodb';
|
|
10
10
|
import { aggregateClusters, findOneClusters } from '../service/clusters.service.js';
|
|
11
11
|
|
|
@@ -1424,7 +1424,7 @@ export async function summaryList( req, res ) {
|
|
|
1424
1424
|
'avg': { 'field': 'ComplianceScore' },
|
|
1425
1425
|
},
|
|
1426
1426
|
'audited_trustScore': {
|
|
1427
|
-
'filter': { 'terms': { 'auditStatus.keyword': [ 'Audited', '
|
|
1427
|
+
'filter': { 'terms': { 'auditStatus.keyword': [ 'Audited', 'Re-Audited' ] } },
|
|
1428
1428
|
'aggs': {
|
|
1429
1429
|
'avg_trustScore': {
|
|
1430
1430
|
'avg': { 'field': 'trustScore' },
|
|
@@ -1659,19 +1659,118 @@ export async function summaryList( req, res ) {
|
|
|
1659
1659
|
let RMEmail = '';
|
|
1660
1660
|
let clusterName='';
|
|
1661
1661
|
if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
|
|
1662
|
-
const
|
|
1663
|
-
|
|
1664
|
-
|
|
1662
|
+
const rmListQuery =[
|
|
1663
|
+
{
|
|
1664
|
+
$match: {
|
|
1665
|
+
$and: [
|
|
1666
|
+
{
|
|
1667
|
+
clientId: { $eq: inputData?.clientId },
|
|
1668
|
+
},
|
|
1669
|
+
{
|
|
1670
|
+
configureType: { $eq: 'user' },
|
|
1671
|
+
},
|
|
1672
|
+
],
|
|
1673
|
+
},
|
|
1674
|
+
},
|
|
1675
|
+
{
|
|
1676
|
+
$unwind: {
|
|
1677
|
+
path: '$userList', preserveNullAndEmptyArrays: true,
|
|
1678
|
+
},
|
|
1679
|
+
},
|
|
1680
|
+
{
|
|
1681
|
+
$group: {
|
|
1682
|
+
_id: null,
|
|
1683
|
+
list: { $addToSet: '$userList.email' },
|
|
1684
|
+
},
|
|
1685
|
+
},
|
|
1686
|
+
{
|
|
1687
|
+
$project: {
|
|
1688
|
+
_id: 0,
|
|
1689
|
+
list: 1,
|
|
1690
|
+
},
|
|
1691
|
+
},
|
|
1692
|
+
];
|
|
1693
|
+
const getRMList = await aggregateEyeTestConfig( rmListQuery );
|
|
1694
|
+
let getCluster = [];
|
|
1695
|
+
if ( getRMList && getRMList?.length > 0 ) {
|
|
1696
|
+
const getRMQuery = [
|
|
1697
|
+
{
|
|
1698
|
+
$unwind: {
|
|
1699
|
+
path: '$Teamlead', preserveNullAndEmptyArrays: true,
|
|
1700
|
+
},
|
|
1701
|
+
},
|
|
1702
|
+
{
|
|
1703
|
+
$match: {
|
|
1704
|
+
$and: [
|
|
1705
|
+
{ 'stores.storeId': { $eq: element?._source?.storeId } },
|
|
1706
|
+
{
|
|
1707
|
+
'Teamlead.email': { $in: getRMList[0].list },
|
|
1708
|
+
},
|
|
1709
|
+
],
|
|
1710
|
+
},
|
|
1711
|
+
},
|
|
1712
|
+
{
|
|
1713
|
+
$group: {
|
|
1714
|
+
_id: null,
|
|
1715
|
+
clusterName: { $addToSet: '$clusterName' },
|
|
1716
|
+
rmList: { $addToSet: '$Teamlead.email' },
|
|
1717
|
+
},
|
|
1718
|
+
},
|
|
1719
|
+
{
|
|
1720
|
+
$project: {
|
|
1721
|
+
_id: 0,
|
|
1722
|
+
clusterName: 1,
|
|
1723
|
+
rmList: 1,
|
|
1724
|
+
},
|
|
1725
|
+
},
|
|
1726
|
+
];
|
|
1727
|
+
getCluster = await aggregateClusters( getRMQuery );
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
1731
|
+
RMEmail =( getCluster && getCluster?.rmList?.length > 0 )? getCluster?.rmList?.toString() : '';
|
|
1732
|
+
clusterName = ( getCluster && getCluster?.clusterName?.length > 0 )? getCluster?.clusterName?.toString() : '';
|
|
1665
1733
|
}
|
|
1666
|
-
if ( RMEmail ) {
|
|
1667
|
-
const temp = await
|
|
1668
|
-
|
|
1734
|
+
if ( RMEmail && RMEmail !== '' ) {
|
|
1735
|
+
const temp = await aggregateUser( [
|
|
1736
|
+
{
|
|
1737
|
+
$match: {
|
|
1738
|
+
$and: [
|
|
1739
|
+
{
|
|
1740
|
+
email: { $in: getCluster?.rmList },
|
|
1741
|
+
},
|
|
1742
|
+
{
|
|
1743
|
+
isActive: true,
|
|
1744
|
+
},
|
|
1745
|
+
{
|
|
1746
|
+
role: { $eq: 'admin' },
|
|
1747
|
+
},
|
|
1748
|
+
],
|
|
1749
|
+
},
|
|
1750
|
+
},
|
|
1751
|
+
{
|
|
1752
|
+
$group: {
|
|
1753
|
+
_id: null,
|
|
1754
|
+
user: { $addToSet: '$userName' },
|
|
1755
|
+
},
|
|
1756
|
+
},
|
|
1757
|
+
{
|
|
1758
|
+
$project: {
|
|
1759
|
+
_id: 0,
|
|
1760
|
+
user: 1,
|
|
1761
|
+
},
|
|
1762
|
+
},
|
|
1763
|
+
] );
|
|
1764
|
+
if ( temp && temp?.user?.length >0 ) {
|
|
1765
|
+
RMName = temp?.[0]?.user?.toString( '' );
|
|
1766
|
+
}
|
|
1767
|
+
logger.info( { RMEmail: RMEmail } );
|
|
1669
1768
|
}
|
|
1670
1769
|
if ( element?._source?.type == 'physical' ) {
|
|
1671
1770
|
exportData.push( {
|
|
1672
1771
|
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1673
|
-
'RM Name': RMName,
|
|
1674
|
-
'Cluster Name': clusterName,
|
|
1772
|
+
...( req?.user?.userType === 'superadmin' && { 'RM Name': RMName } ),
|
|
1773
|
+
...( req?.user?.userType !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1675
1774
|
'Store Name': element?._source?.storeName,
|
|
1676
1775
|
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1677
1776
|
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
@@ -1689,7 +1788,8 @@ export async function summaryList( req, res ) {
|
|
|
1689
1788
|
} else {
|
|
1690
1789
|
exportData.push( {
|
|
1691
1790
|
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1692
|
-
'
|
|
1791
|
+
...( req?.user?.userType === 'superadmin' && { 'RM Name': RMName } ),
|
|
1792
|
+
...( req?.user?.userType !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1693
1793
|
'Store Name': element?._source?.storeName,
|
|
1694
1794
|
'Store Name': element?._source?.storeName,
|
|
1695
1795
|
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
@@ -1887,7 +1987,7 @@ export async function summaryCard( req, res ) {
|
|
|
1887
1987
|
|
|
1888
1988
|
'completedFiles': {
|
|
1889
1989
|
filter: {
|
|
1890
|
-
terms: { 'auditStatus.keyword': [ 'Audited', '
|
|
1990
|
+
terms: { 'auditStatus.keyword': [ 'Audited', 'Re-Audited' ] },
|
|
1891
1991
|
},
|
|
1892
1992
|
},
|
|
1893
1993
|
|
|
@@ -1918,7 +2018,7 @@ export async function summaryCard( req, res ) {
|
|
|
1918
2018
|
|
|
1919
2019
|
'trustScore': {
|
|
1920
2020
|
filter: {
|
|
1921
|
-
terms: { 'auditStatus.keyword': [ 'Audited', '
|
|
2021
|
+
terms: { 'auditStatus.keyword': [ 'Audited', 'Re-Audited' ] },
|
|
1922
2022
|
},
|
|
1923
2023
|
aggs: {
|
|
1924
2024
|
avg_val: { avg: { field: 'trustScore' } },
|
|
@@ -1978,7 +2078,7 @@ export async function summaryCard( req, res ) {
|
|
|
1978
2078
|
initialValue.totalFiles =temp?.totalFiles?.value;
|
|
1979
2079
|
initialValue.completedFiles =temp?.completedFiles?.doc_count;
|
|
1980
2080
|
initialValue.completedRatio =Math.round( temp?.completedRatio?.value || 0 );
|
|
1981
|
-
initialValue.tangoScore =Math.round( temp?.tangoScore?.value || 0 );
|
|
2081
|
+
initialValue.tangoScore =Math.round( temp?.tangoScore?.value || 0 )+ ' %';
|
|
1982
2082
|
initialValue.tangoScoreTrend =temp?.tangoScoreTrend?.value || 0;
|
|
1983
2083
|
initialValue.trustScore =temp?.trustScore?.avg_val?.value == null || temp?.trustScore?.avg_val?.value === undefined ? 'NA':Math.round( temp?.trustScore?.avg_val?.value );
|
|
1984
2084
|
initialValue.trend = initialValue.tangoScoreTrend < 0? false : true;
|
|
@@ -11,3 +11,7 @@ export function findOneEyeTestConfig( query, field ) {
|
|
|
11
11
|
export function findEyeTestConfig( query, field ) {
|
|
12
12
|
return eyeTestConfigurationModel.find( query, field );
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export function aggregateEyeTestConfig( query ) {
|
|
16
|
+
return eyeTestConfigurationModel.aggregate( query );
|
|
17
|
+
}
|