tango-app-api-audit 3.4.3-alpha.0 → 3.4.3-alpha.10
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 +1 -1
- package/src/controllers/audit.controllers.js +82 -0
- package/src/controllers/traxAudit.controllers.js +258 -41
- package/src/docs/traxAudit.docs.js +110 -2
- package/src/dtos/audit.dtos.js +0 -2
- package/src/dtos/traxAudit.dtos.js +30 -7
- package/src/routes/audit.routes.js +4 -1
- package/src/routes/traxAudit.routes.js +10 -15
- package/src/service/auditUserWallet.service.js +4 -1
- package/src/service/empDetectionOutput.service.js +2 -2
- package/src/service/storeEmpDetection.service.js +5 -0
- package/src/service/userEmpDetection.service.js +2 -0
- package/src/validation/traxAuditValidation.js +47 -1
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
signedUrl,
|
|
10
10
|
getDate, getDateWithCustomizeTime,
|
|
11
11
|
getUTC,
|
|
12
|
+
getOpenSearchData,
|
|
12
13
|
} from 'tango-app-api-middleware';
|
|
13
14
|
import {
|
|
14
15
|
aggregateUserAudit,
|
|
@@ -3567,6 +3568,43 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3567
3568
|
},
|
|
3568
3569
|
},
|
|
3569
3570
|
];
|
|
3571
|
+
|
|
3572
|
+
const mappingInprogressCount = [
|
|
3573
|
+
{
|
|
3574
|
+
$match: {
|
|
3575
|
+
fileDate: { $eq: latestTraxDate },
|
|
3576
|
+
},
|
|
3577
|
+
},
|
|
3578
|
+
{
|
|
3579
|
+
$project: {
|
|
3580
|
+
inprogressAuditCount: {
|
|
3581
|
+
$cond: [
|
|
3582
|
+
{ $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3583
|
+
],
|
|
3584
|
+
},
|
|
3585
|
+
inprogressTraxCount: {
|
|
3586
|
+
$cond: [
|
|
3587
|
+
{ $and: [ { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3588
|
+
],
|
|
3589
|
+
},
|
|
3590
|
+
|
|
3591
|
+
},
|
|
3592
|
+
},
|
|
3593
|
+
{
|
|
3594
|
+
$group: {
|
|
3595
|
+
_id: null,
|
|
3596
|
+
inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3597
|
+
inprogressTraxCount: { $sum: '$inprogressTraxCount' },
|
|
3598
|
+
},
|
|
3599
|
+
},
|
|
3600
|
+
{
|
|
3601
|
+
$project: {
|
|
3602
|
+
_id: 0,
|
|
3603
|
+
inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3604
|
+
inprogressTraxCount: { $ifNull: [ '$inprogressTraxCount', 0 ] },
|
|
3605
|
+
},
|
|
3606
|
+
},
|
|
3607
|
+
];
|
|
3570
3608
|
// const binaryInprogressCount=[
|
|
3571
3609
|
// {
|
|
3572
3610
|
// $match: {
|
|
@@ -3651,6 +3689,8 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3651
3689
|
const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
|
|
3652
3690
|
const getInprogressCount = await aggregateStoreAudit( inprogressCount );
|
|
3653
3691
|
const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
|
|
3692
|
+
const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3693
|
+
logger.info( { getMappingInprogressCount: getMappingInprogressCount } );
|
|
3654
3694
|
// const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3655
3695
|
if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
|
|
3656
3696
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -3671,6 +3711,12 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3671
3711
|
} else {
|
|
3672
3712
|
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
|
|
3673
3713
|
}
|
|
3714
|
+
|
|
3715
|
+
if ( getMappingInprogressCount.length > 0 ) {
|
|
3716
|
+
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0].totalTraxAuditCount > getMappingInprogressCount[0].inprogressTraxCount ? getTotalTraxAudit[0].totalTraxAuditCount - getMappingInprogressCount[0].inprogressTraxCount : 0;
|
|
3717
|
+
} else {
|
|
3718
|
+
notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
|
|
3719
|
+
}
|
|
3674
3720
|
return res.sendSuccess( { result: notAssignedCount } );
|
|
3675
3721
|
} catch ( error ) {
|
|
3676
3722
|
const err = error.message || 'Internal Server Error';
|
|
@@ -4302,3 +4348,39 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4302
4348
|
}
|
|
4303
4349
|
}
|
|
4304
4350
|
|
|
4351
|
+
export async function auditViewLogs( req, res ) {
|
|
4352
|
+
try {
|
|
4353
|
+
const inputData = req.query;
|
|
4354
|
+
const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4355
|
+
let downTimeQuery = {
|
|
4356
|
+
'size': 100,
|
|
4357
|
+
'query': {
|
|
4358
|
+
'bool': {
|
|
4359
|
+
'must': [
|
|
4360
|
+
{
|
|
4361
|
+
'term': {
|
|
4362
|
+
'doc.logData.fileDate.keyword': dayjs( inputData.fileDate ).format( 'DD-MM-YYYY' ),
|
|
4363
|
+
},
|
|
4364
|
+
},
|
|
4365
|
+
{
|
|
4366
|
+
'term': {
|
|
4367
|
+
'doc.logData.storeId.keyword': inputData.storeId,
|
|
4368
|
+
},
|
|
4369
|
+
},
|
|
4370
|
+
{
|
|
4371
|
+
'term': {
|
|
4372
|
+
'doc.logData.moduleType.keyword': inputData.moduleType,
|
|
4373
|
+
},
|
|
4374
|
+
},
|
|
4375
|
+
],
|
|
4376
|
+
|
|
4377
|
+
},
|
|
4378
|
+
},
|
|
4379
|
+
};
|
|
4380
|
+
const downtime = await getOpenSearchData( parsedOpenSearch.auditLog, downTimeQuery );
|
|
4381
|
+
return res.sendSuccess( downtime );
|
|
4382
|
+
} catch ( err ) {
|
|
4383
|
+
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
|
|
@@ -4,16 +4,19 @@ import { countDocumentsStore, findOneStore } from '../service/store.service.js';
|
|
|
4
4
|
import { findOneUser } from '../service/user.service.js';
|
|
5
5
|
import { aggregateUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
|
|
6
6
|
import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
7
|
-
import { aggregateClient } from '../service/client.service.js';
|
|
7
|
+
import { aggregateClient, findOneClient } from '../service/client.service.js';
|
|
8
8
|
import dayjs from 'dayjs';
|
|
9
9
|
import { aggregateAssignAudit } from '../service/assignAudit.service.js';
|
|
10
|
-
import { aggregateStoreEmpDetection, updateManyStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
11
|
-
import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
10
|
+
import { aggregateStoreEmpDetection, updateManyStoreEmpDetection, updateOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
11
|
+
import { listQueue, sendMessageToQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
12
12
|
import _ from 'lodash';
|
|
13
13
|
import mongoose from 'mongoose';
|
|
14
|
-
import { findOneAuditLog
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
import { findOneAuditLog, createAuditLog,
|
|
15
|
+
} from '../service/auditLog.service.js';
|
|
16
|
+
import {
|
|
17
|
+
findOneUserEmpDetection,
|
|
18
|
+
} from '../service/userEmpDetection.service.js';
|
|
19
|
+
import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
|
|
17
20
|
// export async function getDetectionAuditFile( req, res ) {
|
|
18
21
|
// try {
|
|
19
22
|
// const bucket = JSON.parse( process.env.BUCKET );
|
|
@@ -334,13 +337,13 @@ import { findOneAuditLog } from '../service/auditLog.service.js';
|
|
|
334
337
|
// const data = await signedUrl( fetchData );
|
|
335
338
|
// const mapimg = {
|
|
336
339
|
// img_path: data,
|
|
337
|
-
// img_name: indexes[
|
|
338
|
-
// img_id:
|
|
340
|
+
// img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
341
|
+
// img_id: img[3],
|
|
339
342
|
// };
|
|
340
343
|
// files.push( {
|
|
341
344
|
// img_path: data,
|
|
342
|
-
//
|
|
343
|
-
// img_id:
|
|
345
|
+
// img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
346
|
+
// img_id: img[3],
|
|
344
347
|
// selected: false,
|
|
345
348
|
// dropped: false,
|
|
346
349
|
// count: 1,
|
|
@@ -709,7 +712,7 @@ export async function workSpace( req, res ) {
|
|
|
709
712
|
{ clientId: { $in: clientList } },
|
|
710
713
|
{ userId: { $eq: req.user._id } },
|
|
711
714
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
712
|
-
{ createdAt: { $gte:
|
|
715
|
+
{ createdAt: { $gte: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ) } },
|
|
713
716
|
{ createdAt: { $lte: dateRange.end } },
|
|
714
717
|
],
|
|
715
718
|
},
|
|
@@ -742,6 +745,8 @@ export async function workSpace( req, res ) {
|
|
|
742
745
|
},
|
|
743
746
|
];
|
|
744
747
|
|
|
748
|
+
logger.info( { moduleType: inputData.moduleType, key: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ), dateStart: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ), end: dateRange.end, user: req.user._id, client: clientList } );
|
|
749
|
+
|
|
745
750
|
const userAsignAudit = [
|
|
746
751
|
{
|
|
747
752
|
$match: {
|
|
@@ -794,10 +799,11 @@ export async function workSpace( req, res ) {
|
|
|
794
799
|
},
|
|
795
800
|
];
|
|
796
801
|
|
|
797
|
-
const auditUserCount =
|
|
798
|
-
const userIncompleteFilesCount =
|
|
802
|
+
const auditUserCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
803
|
+
const userIncompleteFilesCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
804
|
+
logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
|
|
799
805
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
800
|
-
const completedStoresCount =
|
|
806
|
+
const completedStoresCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
801
807
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
802
808
|
const auditStoreData = await aggregateTraxAuditData(
|
|
803
809
|
auditStoreDataQuery,
|
|
@@ -1694,7 +1700,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1694
1700
|
},
|
|
1695
1701
|
);
|
|
1696
1702
|
}
|
|
1697
|
-
const count =
|
|
1703
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1698
1704
|
if ( count.length == 0 ) {
|
|
1699
1705
|
return res.sendError( 'No Data Found', 204 );
|
|
1700
1706
|
}
|
|
@@ -1764,7 +1770,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1764
1770
|
{
|
|
1765
1771
|
$limit: limit,
|
|
1766
1772
|
} );
|
|
1767
|
-
const result =
|
|
1773
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1768
1774
|
|
|
1769
1775
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1770
1776
|
} catch ( error ) {
|
|
@@ -1916,6 +1922,125 @@ export async function clientMetrics( req, res ) {
|
|
|
1916
1922
|
},
|
|
1917
1923
|
];
|
|
1918
1924
|
|
|
1925
|
+
const MappingQuery =[
|
|
1926
|
+
{
|
|
1927
|
+
$match: {
|
|
1928
|
+
$and: filter,
|
|
1929
|
+
},
|
|
1930
|
+
},
|
|
1931
|
+
{
|
|
1932
|
+
$group: {
|
|
1933
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
|
|
1934
|
+
fileDate: { $last: '$fileDate' },
|
|
1935
|
+
clientId: { $last: '$clientId' },
|
|
1936
|
+
clientName: { $last: '$clientName' },
|
|
1937
|
+
moduleType: { $last: '$moduleType' },
|
|
1938
|
+
installedStore: { $last: '$installedStore' },
|
|
1939
|
+
queueName: { $last: '$queueName' },
|
|
1940
|
+
totalFilesCount: { $sum: 1 },
|
|
1941
|
+
},
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
$project: {
|
|
1945
|
+
fileDate: 1,
|
|
1946
|
+
clientId: 1,
|
|
1947
|
+
clientName: 1,
|
|
1948
|
+
queueName: 1,
|
|
1949
|
+
installedStore: 1,
|
|
1950
|
+
totalFilesCount: 1,
|
|
1951
|
+
moduleType: 1,
|
|
1952
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
1953
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
1954
|
+
},
|
|
1955
|
+
},
|
|
1956
|
+
{
|
|
1957
|
+
$lookup: {
|
|
1958
|
+
'from': 'storeEmpDetection',
|
|
1959
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
|
|
1960
|
+
'pipeline': [
|
|
1961
|
+
|
|
1962
|
+
{
|
|
1963
|
+
$match: {
|
|
1964
|
+
$expr: {
|
|
1965
|
+
$and: storeAuditFilter,
|
|
1966
|
+
},
|
|
1967
|
+
},
|
|
1968
|
+
},
|
|
1969
|
+
{
|
|
1970
|
+
$project: {
|
|
1971
|
+
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
1972
|
+
notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
|
|
1973
|
+
inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
1974
|
+
},
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
$group: {
|
|
1978
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
1979
|
+
completedStores: { $sum: '$completedStores' },
|
|
1980
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
1981
|
+
notAssignedStores: { $sum: '$notAssignedStores' },
|
|
1982
|
+
fileCount: { $sum: 1 },
|
|
1983
|
+
},
|
|
1984
|
+
},
|
|
1985
|
+
{
|
|
1986
|
+
$project: {
|
|
1987
|
+
_id: 0,
|
|
1988
|
+
completedStores: 1,
|
|
1989
|
+
inprogressStores: 1,
|
|
1990
|
+
notAssignedStores: 1,
|
|
1991
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1992
|
+
completionPercentage: { $ifNull: [
|
|
1993
|
+
{
|
|
1994
|
+
$round: [ {
|
|
1995
|
+
$multiply: [
|
|
1996
|
+
100, {
|
|
1997
|
+
$divide: [
|
|
1998
|
+
'$completedStores', '$$totalAuditFiles',
|
|
1999
|
+
],
|
|
2000
|
+
},
|
|
2001
|
+
],
|
|
2002
|
+
}, 1 ],
|
|
2003
|
+
|
|
2004
|
+
},
|
|
2005
|
+
0,
|
|
2006
|
+
],
|
|
2007
|
+
},
|
|
2008
|
+
},
|
|
2009
|
+
},
|
|
2010
|
+
], 'as': 'binaryAudit',
|
|
2011
|
+
},
|
|
2012
|
+
},
|
|
2013
|
+
{
|
|
2014
|
+
$unwind: {
|
|
2015
|
+
path: '$binaryAudit',
|
|
2016
|
+
preserveNullAndEmptyArrays: true,
|
|
2017
|
+
},
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
$project: {
|
|
2021
|
+
_id: 0,
|
|
2022
|
+
fileDate: 1,
|
|
2023
|
+
clientId: 1,
|
|
2024
|
+
clientName: 1,
|
|
2025
|
+
totalFilesCount: 1,
|
|
2026
|
+
moduleType: 1,
|
|
2027
|
+
value: {
|
|
2028
|
+
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
2029
|
+
},
|
|
2030
|
+
installedStore: 1,
|
|
2031
|
+
// notAssignedStores: '$binaryAudit.notAssignedStores',
|
|
2032
|
+
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
2033
|
+
// fileCount: '$binaryAudit.fileCount',
|
|
2034
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
2035
|
+
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
2036
|
+
completedStores: '$binaryAudit.completedStores',
|
|
2037
|
+
completionPercentage: '$binaryAudit.completionPercentage',
|
|
2038
|
+
|
|
2039
|
+
},
|
|
2040
|
+
},
|
|
2041
|
+
];
|
|
2042
|
+
|
|
2043
|
+
|
|
1919
2044
|
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
1920
2045
|
query.push(
|
|
1921
2046
|
{
|
|
@@ -1947,7 +2072,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1947
2072
|
);
|
|
1948
2073
|
}
|
|
1949
2074
|
|
|
1950
|
-
const count = await aggregateTraxAuditData( query );
|
|
2075
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
1951
2076
|
logger.info( { count: count } );
|
|
1952
2077
|
if ( count.length == 0 ) {
|
|
1953
2078
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -1980,7 +2105,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1980
2105
|
}
|
|
1981
2106
|
|
|
1982
2107
|
logger.info( { query: query } );
|
|
1983
|
-
const result = await aggregateTraxAuditData( query );
|
|
2108
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
1984
2109
|
if ( result.length == 0 ) {
|
|
1985
2110
|
return res.sendError( 'No Data Found', 204 );
|
|
1986
2111
|
}
|
|
@@ -2423,7 +2548,9 @@ export async function storeMetrics( req, res ) {
|
|
|
2423
2548
|
},
|
|
2424
2549
|
);
|
|
2425
2550
|
}
|
|
2426
|
-
|
|
2551
|
+
logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
|
|
2552
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2553
|
+
|
|
2427
2554
|
|
|
2428
2555
|
if ( count.length == 0 ) {
|
|
2429
2556
|
return res.sendError( 'No data Found', 204 );
|
|
@@ -2438,7 +2565,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2438
2565
|
} else {
|
|
2439
2566
|
query.push( { $limit: 10000 } );
|
|
2440
2567
|
}
|
|
2441
|
-
const result =
|
|
2568
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2442
2569
|
if ( inputData.isExport ) {
|
|
2443
2570
|
const exportdata = [];
|
|
2444
2571
|
result.forEach( ( element ) => {
|
|
@@ -2741,7 +2868,7 @@ export async function userMetrics( req, res ) {
|
|
|
2741
2868
|
);
|
|
2742
2869
|
}
|
|
2743
2870
|
|
|
2744
|
-
const count =
|
|
2871
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2745
2872
|
if ( count.length == 0 ) {
|
|
2746
2873
|
return res.sendError( 'No Data Found', 204 );
|
|
2747
2874
|
}
|
|
@@ -2775,7 +2902,7 @@ export async function userMetrics( req, res ) {
|
|
|
2775
2902
|
'Product Type': '$value',
|
|
2776
2903
|
// 'Mapping Percentage': '$mappingPerc',
|
|
2777
2904
|
};
|
|
2778
|
-
|
|
2905
|
+
[ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?
|
|
2779
2906
|
query.push(
|
|
2780
2907
|
{
|
|
2781
2908
|
$project: detection,
|
|
@@ -2789,7 +2916,7 @@ export async function userMetrics( req, res ) {
|
|
|
2789
2916
|
}
|
|
2790
2917
|
|
|
2791
2918
|
|
|
2792
|
-
const result =
|
|
2919
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2793
2920
|
if ( inputData.isExport ) {
|
|
2794
2921
|
await download( result, res );
|
|
2795
2922
|
return;
|
|
@@ -2933,7 +3060,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2933
3060
|
},
|
|
2934
3061
|
);
|
|
2935
3062
|
}
|
|
2936
|
-
const count =
|
|
3063
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2937
3064
|
if ( count.length == 0 ) {
|
|
2938
3065
|
return res.sendError( 'No Data Found', 204 );
|
|
2939
3066
|
}
|
|
@@ -2949,7 +3076,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2949
3076
|
} );
|
|
2950
3077
|
}
|
|
2951
3078
|
|
|
2952
|
-
const result =
|
|
3079
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2953
3080
|
if ( inputData.isExport ) {
|
|
2954
3081
|
const exportdata = [];
|
|
2955
3082
|
result.forEach( ( element ) => {
|
|
@@ -3143,7 +3270,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
3143
3270
|
},
|
|
3144
3271
|
];
|
|
3145
3272
|
|
|
3146
|
-
const storeAudit =
|
|
3273
|
+
const storeAudit = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3147
3274
|
if ( storeAudit.length > 0 ) {
|
|
3148
3275
|
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
3149
3276
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -3274,7 +3401,7 @@ export async function summarySplit( req, res ) {
|
|
|
3274
3401
|
},
|
|
3275
3402
|
},
|
|
3276
3403
|
];
|
|
3277
|
-
const result =
|
|
3404
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3278
3405
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3279
3406
|
result[0].totalCount = totalCount[0]?.total;
|
|
3280
3407
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3421,7 +3548,7 @@ export async function overviewTable( req, res ) {
|
|
|
3421
3548
|
},
|
|
3422
3549
|
);
|
|
3423
3550
|
}
|
|
3424
|
-
const count =
|
|
3551
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3425
3552
|
if ( count.length == 0 ) {
|
|
3426
3553
|
return res.sendError( 'No Data Found', 204 );
|
|
3427
3554
|
}
|
|
@@ -3436,7 +3563,7 @@ export async function overviewTable( req, res ) {
|
|
|
3436
3563
|
$limit: limit,
|
|
3437
3564
|
} );
|
|
3438
3565
|
}
|
|
3439
|
-
const result =
|
|
3566
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3440
3567
|
if ( inputData.isExport ) {
|
|
3441
3568
|
const exportdata = [];
|
|
3442
3569
|
result.forEach( ( element ) => {
|
|
@@ -3809,13 +3936,13 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3809
3936
|
const data = await signedUrl( fetchData );
|
|
3810
3937
|
const mapimg = {
|
|
3811
3938
|
img_path: data,
|
|
3812
|
-
img_name: indexes[
|
|
3813
|
-
img_id:
|
|
3939
|
+
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
3940
|
+
img_id: img[3],
|
|
3814
3941
|
};
|
|
3815
3942
|
files.push( {
|
|
3816
3943
|
img_path: data,
|
|
3817
|
-
img_name: indexes[
|
|
3818
|
-
img_id:
|
|
3944
|
+
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
3945
|
+
img_id: img[3],
|
|
3819
3946
|
selected: false,
|
|
3820
3947
|
dropped: false,
|
|
3821
3948
|
count: 1,
|
|
@@ -3834,7 +3961,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3834
3961
|
userId: req.user._id,
|
|
3835
3962
|
storeId: msg.storeId,
|
|
3836
3963
|
clientId: msg.storeId.split( '-' )[0],
|
|
3837
|
-
auditType: 'Audit',
|
|
3964
|
+
auditType: msg.auditType || 'Audit',
|
|
3838
3965
|
fileDate: msg.fileDate,
|
|
3839
3966
|
inputBucketName: msg.inputBucketName,
|
|
3840
3967
|
folderPath: msg.folderPath,
|
|
@@ -3855,7 +3982,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3855
3982
|
userId: req.user._id,
|
|
3856
3983
|
storeId: msg.storeId,
|
|
3857
3984
|
clientId: msg.storeId.split( '-' )[0],
|
|
3858
|
-
auditType: 'Audit',
|
|
3985
|
+
auditType: msg.auditType || 'Audit',
|
|
3859
3986
|
fileDate: msg.fileDate,
|
|
3860
3987
|
folderPath: msg.folderPath,
|
|
3861
3988
|
inputBucketName: msg.inputBucketName,
|
|
@@ -3918,7 +4045,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3918
4045
|
queueName: inputData.queueName,
|
|
3919
4046
|
storeId: storeId,
|
|
3920
4047
|
fileDate: fileDate,
|
|
3921
|
-
auditType: 'Audit',
|
|
4048
|
+
auditType: msg.auditType || 'Audit',
|
|
3922
4049
|
auditId: insertData._id,
|
|
3923
4050
|
userId: insertData.userId,
|
|
3924
4051
|
moduleType: inputData.moduleType,
|
|
@@ -3942,7 +4069,7 @@ export async function saveDraft( req, res ) {
|
|
|
3942
4069
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
3943
4070
|
const inputData = req.body;
|
|
3944
4071
|
inputData.userId = req.user._id;
|
|
3945
|
-
const getUserAuditData = await
|
|
4072
|
+
const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
|
|
3946
4073
|
if ( !getUserAuditData ) {
|
|
3947
4074
|
return res.sendError( 'No Data Found', 204 );
|
|
3948
4075
|
}
|
|
@@ -3960,7 +4087,6 @@ export async function saveDraft( req, res ) {
|
|
|
3960
4087
|
const storeQuery = {
|
|
3961
4088
|
storeId: inputData.storeId,
|
|
3962
4089
|
fileDate: inputData.fileDate,
|
|
3963
|
-
zoneName: inputData.zoneName,
|
|
3964
4090
|
};
|
|
3965
4091
|
|
|
3966
4092
|
let storeRecord = {
|
|
@@ -4000,8 +4126,8 @@ export async function saveDraft( req, res ) {
|
|
|
4000
4126
|
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4001
4127
|
}
|
|
4002
4128
|
await createAuditLog( inputData );
|
|
4003
|
-
await
|
|
4004
|
-
await
|
|
4129
|
+
await updateOneUserEmpDetection( userQuery, userRecord );
|
|
4130
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4005
4131
|
return res.sendSuccess( {
|
|
4006
4132
|
result: 'The file has been drafted successfully',
|
|
4007
4133
|
} );
|
|
@@ -4045,8 +4171,13 @@ export async function getDraftedData( req, res ) {
|
|
|
4045
4171
|
export async function save( req, res ) {
|
|
4046
4172
|
try {
|
|
4047
4173
|
const inputData = req.body;
|
|
4048
|
-
const
|
|
4174
|
+
const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
|
|
4175
|
+
inputData.clientId = getUserAuditData.clientId;
|
|
4176
|
+
const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
|
|
4177
|
+
const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
|
|
4049
4178
|
if ( data ) {
|
|
4179
|
+
await updateOneUserEmpDetection( { _id: inputData.auditId }, { auditStatus: 'completed', afterCount: inputData.employeeCount } );
|
|
4180
|
+
await updateOneStoreEmpDetection( query, { status: 'completed', afterCount: inputData.employeeCount } );
|
|
4050
4181
|
return res.sendSuccess( { result: 'Updated Successfully' } );
|
|
4051
4182
|
} else {
|
|
4052
4183
|
return res.sendError( 'something went wrong', 403 );
|
|
@@ -4061,3 +4192,89 @@ export async function save( req, res ) {
|
|
|
4061
4192
|
return res.sendError( err, 500 );
|
|
4062
4193
|
}
|
|
4063
4194
|
}
|
|
4195
|
+
|
|
4196
|
+
export async function reTrigger( req, res ) {
|
|
4197
|
+
try {
|
|
4198
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4199
|
+
const inputData = req.body;
|
|
4200
|
+
const message = req.sqs;
|
|
4201
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
4202
|
+
const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
|
|
4203
|
+
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : getQueueName?.auditConfigs?.traxQueueName?.mobileDetection;
|
|
4204
|
+
if ( !getQueueName || queueName == '' ) {
|
|
4205
|
+
return res.sendError( 'queueName does not create', 400 );
|
|
4206
|
+
}
|
|
4207
|
+
const msg = {
|
|
4208
|
+
storeId: message.storeId,
|
|
4209
|
+
fileDate: message.fileDate,
|
|
4210
|
+
moduleType: message.moduleType,
|
|
4211
|
+
inputBucketName: message.inputBucketName,
|
|
4212
|
+
questionType: message.questionType,
|
|
4213
|
+
question: message.question,
|
|
4214
|
+
folderPath: message.folderPath,
|
|
4215
|
+
fileCount: message.fileCount,
|
|
4216
|
+
};
|
|
4217
|
+
const sqsProduceQueue = {
|
|
4218
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
4219
|
+
MessageBody: JSON.stringify( msg ),
|
|
4220
|
+
};
|
|
4221
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
4222
|
+
if ( sqsQueue?.errorCode ) {
|
|
4223
|
+
const error = sqsQueue?.errorMsg;
|
|
4224
|
+
const code = sqsQueue?.errorCode;
|
|
4225
|
+
return res.sendError( error, code );
|
|
4226
|
+
} else {
|
|
4227
|
+
if ( req.audit.status !== 'completed' ) {
|
|
4228
|
+
const userRecord = {
|
|
4229
|
+
auditStatus: 'skipped',
|
|
4230
|
+
isDraft: false,
|
|
4231
|
+
};
|
|
4232
|
+
const query = {
|
|
4233
|
+
storeId: inputData.storeId,
|
|
4234
|
+
fileDate: inputData.fileDate,
|
|
4235
|
+
auditStatus: req.audit.status,
|
|
4236
|
+
moduleType: inputData.moduleType,
|
|
4237
|
+
|
|
4238
|
+
};
|
|
4239
|
+
await updateOneUserEmpDetection( query, userRecord );
|
|
4240
|
+
}
|
|
4241
|
+
|
|
4242
|
+
const storeQuery = {
|
|
4243
|
+
storeId: inputData.storeId,
|
|
4244
|
+
fileDate: inputData.fileDate,
|
|
4245
|
+
moduleType: inputData.moduleType,
|
|
4246
|
+
|
|
4247
|
+
};
|
|
4248
|
+
|
|
4249
|
+
const storeRecord = {
|
|
4250
|
+
status: 'not_assign',
|
|
4251
|
+
};
|
|
4252
|
+
|
|
4253
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4254
|
+
const logData = {
|
|
4255
|
+
userId: req.user._id,
|
|
4256
|
+
userName: req.user.userName,
|
|
4257
|
+
logType: 'traxAudit',
|
|
4258
|
+
logSubType: 'reTrigger',
|
|
4259
|
+
logData: {
|
|
4260
|
+
beforeCount: message.fileCount,
|
|
4261
|
+
afterCount: '',
|
|
4262
|
+
fileDate: inputData.fileDate,
|
|
4263
|
+
auditType: req.audit.auditType,
|
|
4264
|
+
storeId: inputData.storeId,
|
|
4265
|
+
moduleType: inputData.moduleType,
|
|
4266
|
+
queueName: queueName,
|
|
4267
|
+
triggerBy: req.user.userName,
|
|
4268
|
+
triggerId: req.user._id,
|
|
4269
|
+
},
|
|
4270
|
+
createdAt: new Date(),
|
|
4271
|
+
};
|
|
4272
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4273
|
+
}
|
|
4274
|
+
return res.sendSuccess( { result: 'The File has been Re-Triggered Succesfully' } );
|
|
4275
|
+
} catch ( error ) {
|
|
4276
|
+
const err = error.message;
|
|
4277
|
+
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|
|
4278
|
+
return res.sendError( err, 500 );
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid } from '../dtos/traxAudit.dtos.js';
|
|
2
|
+
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const traxAuditDocs = {
|
|
5
5
|
|
|
@@ -124,7 +124,7 @@ export const traxAuditDocs = {
|
|
|
124
124
|
requestBody: {
|
|
125
125
|
content: {
|
|
126
126
|
'application/json': {
|
|
127
|
-
schema: j2s(
|
|
127
|
+
schema: j2s( saveBinarySchema ).swagger,
|
|
128
128
|
},
|
|
129
129
|
},
|
|
130
130
|
},
|
|
@@ -317,4 +317,112 @@ export const traxAuditDocs = {
|
|
|
317
317
|
},
|
|
318
318
|
},
|
|
319
319
|
},
|
|
320
|
+
'/v3/trax-audit/save': {
|
|
321
|
+
post: {
|
|
322
|
+
tags: [ 'Trax Audit' ],
|
|
323
|
+
description: `submit the audit file. which is store in the bucket in the json format`,
|
|
324
|
+
operationId: 'save',
|
|
325
|
+
parameters: {},
|
|
326
|
+
requestBody: {
|
|
327
|
+
content: {
|
|
328
|
+
'application/json': {
|
|
329
|
+
schema: j2s( saveSchema ).swagger,
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
responses: {
|
|
334
|
+
200: { description: 'The Audited file has been submited successfully ' },
|
|
335
|
+
401: { description: 'Unauthorized User' },
|
|
336
|
+
422: { description: 'Field Error' },
|
|
337
|
+
500: { description: 'Server Error' },
|
|
338
|
+
204: { description: 'Not Found' },
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
'/v3/trax-audit/save-draft': {
|
|
344
|
+
post: {
|
|
345
|
+
tags: [ 'Trax Audit' ],
|
|
346
|
+
description: `save audited file. which is save in the mongo db`,
|
|
347
|
+
operationId: 'save-draft',
|
|
348
|
+
parameters: {},
|
|
349
|
+
requestBody: {
|
|
350
|
+
content: {
|
|
351
|
+
'application/json': {
|
|
352
|
+
schema: j2s( saveDraftSchema ).swagger,
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
responses: {
|
|
357
|
+
200: { description: 'Successful' },
|
|
358
|
+
401: { description: 'Unauthorized User' },
|
|
359
|
+
422: { description: 'Field Error' },
|
|
360
|
+
500: { description: 'Server Error' },
|
|
361
|
+
204: { description: 'Not Found' },
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
'/v3/trax-audit/get-drafted-data': {
|
|
367
|
+
get: {
|
|
368
|
+
tags: [ 'Trax Audit' ],
|
|
369
|
+
description: 'Get a saved file via DB',
|
|
370
|
+
operationId: 'get-drafted-data',
|
|
371
|
+
parameters: [
|
|
372
|
+
{
|
|
373
|
+
in: 'query',
|
|
374
|
+
name: 'fileDate',
|
|
375
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
376
|
+
require: true,
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
in: 'query',
|
|
380
|
+
name: 'storeId',
|
|
381
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
382
|
+
require: true,
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
in: 'query',
|
|
386
|
+
name: 'moduleType',
|
|
387
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
388
|
+
require: true,
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
in: 'query',
|
|
392
|
+
name: 'userId',
|
|
393
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
394
|
+
require: false,
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
responses: {
|
|
398
|
+
200: { description: 'Successful' },
|
|
399
|
+
401: { description: 'Unauthorized User' },
|
|
400
|
+
422: { description: 'Field Error' },
|
|
401
|
+
500: { description: 'Server Error' },
|
|
402
|
+
204: { description: 'Not Found' },
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
'/v3/trax-audit/metrics/re-trigger': {
|
|
407
|
+
post: {
|
|
408
|
+
tags: [ 'Trax Audit' ],
|
|
409
|
+
description: `Manual re trigger a file`,
|
|
410
|
+
operationId: 'metrics/re-trigger',
|
|
411
|
+
parameters: {},
|
|
412
|
+
requestBody: {
|
|
413
|
+
content: {
|
|
414
|
+
'application/json': {
|
|
415
|
+
schema: j2s( reTriggerValidSchema ).swagger,
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
responses: {
|
|
420
|
+
200: { description: 'Successful' },
|
|
421
|
+
401: { description: 'Unauthorized User' },
|
|
422
|
+
422: { description: 'Field Error' },
|
|
423
|
+
500: { description: 'Server Error' },
|
|
424
|
+
204: { description: 'Not Found' },
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
320
428
|
};
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -96,8 +96,6 @@ export const saveSchema = joi.object( {
|
|
|
96
96
|
employee: joi.array().required(),
|
|
97
97
|
customerCount: joi.number().required(),
|
|
98
98
|
customer: joi.array().required(),
|
|
99
|
-
moduleType: joi.string().required(),
|
|
100
|
-
zoneName: joi.string().required(),
|
|
101
99
|
} );
|
|
102
100
|
|
|
103
101
|
export const saveValid = {
|
|
@@ -45,7 +45,6 @@ export const saveDraftSchema = joi.object(
|
|
|
45
45
|
storeId: joi.string().required(),
|
|
46
46
|
auditId: joi.string().required(),
|
|
47
47
|
moduleType: joi.string().required(),
|
|
48
|
-
zoneName: joi.string().required(),
|
|
49
48
|
auditType: joi.string().required(),
|
|
50
49
|
fileDate: joi.string().required(),
|
|
51
50
|
queueName: joi.string().required(),
|
|
@@ -54,8 +53,6 @@ export const saveDraftSchema = joi.object(
|
|
|
54
53
|
junk: joi.array().optional(),
|
|
55
54
|
employeeCount: joi.number().optional(),
|
|
56
55
|
employee: joi.array().optional(),
|
|
57
|
-
customerCount: joi.number().optional(),
|
|
58
|
-
customer: joi.array().optional(),
|
|
59
56
|
retagCount: joi.number().optional(),
|
|
60
57
|
retagImage: joi.array().optional(),
|
|
61
58
|
},
|
|
@@ -71,7 +68,6 @@ export const getDraftedDataSchema = joi.object(
|
|
|
71
68
|
fileDate: joi.string().required(),
|
|
72
69
|
userId: joi.string().optional(),
|
|
73
70
|
moduleType: joi.string().required(),
|
|
74
|
-
zoneName: joi.string().required(),
|
|
75
71
|
},
|
|
76
72
|
);
|
|
77
73
|
|
|
@@ -79,7 +75,7 @@ export const getDraftedDataValid = {
|
|
|
79
75
|
query: getDraftedDataSchema,
|
|
80
76
|
};
|
|
81
77
|
|
|
82
|
-
export const
|
|
78
|
+
export const saveBinarySchema = joi.object(
|
|
83
79
|
{
|
|
84
80
|
auditId: joi.string().required(),
|
|
85
81
|
storeId: joi.string().required(),
|
|
@@ -93,8 +89,8 @@ export const saveSchema = joi.object(
|
|
|
93
89
|
},
|
|
94
90
|
);
|
|
95
91
|
|
|
96
|
-
export const
|
|
97
|
-
body:
|
|
92
|
+
export const saveBinaryValid = {
|
|
93
|
+
body: saveBinarySchema,
|
|
98
94
|
};
|
|
99
95
|
|
|
100
96
|
export const workSpaceSchema = joi.object(
|
|
@@ -268,3 +264,30 @@ export const overviewTableSchema = joi.object(
|
|
|
268
264
|
export const overviewTableValid= {
|
|
269
265
|
body: overviewTableSchema,
|
|
270
266
|
};
|
|
267
|
+
|
|
268
|
+
export const saveSchema = joi.object( {
|
|
269
|
+
auditId: joi.string().required(),
|
|
270
|
+
storeId: joi.string().required(),
|
|
271
|
+
fileDate: joi.string().required(),
|
|
272
|
+
auditType: joi.string().required(),
|
|
273
|
+
moduleType: joi.string().required(),
|
|
274
|
+
beforeCount: joi.number().required(),
|
|
275
|
+
employeeCount: joi.number().required(),
|
|
276
|
+
employee: joi.array().required(),
|
|
277
|
+
} );
|
|
278
|
+
|
|
279
|
+
export const saveValid = {
|
|
280
|
+
body: saveSchema,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
export const reTriggerValidSchema = joi.object( {
|
|
285
|
+
fileDate: joi.string().required(),
|
|
286
|
+
storeId: joi.string().required(),
|
|
287
|
+
moduleType: joi.string().required(),
|
|
288
|
+
|
|
289
|
+
} );
|
|
290
|
+
|
|
291
|
+
export const reTriggerValid = {
|
|
292
|
+
body: reTriggerValidSchema,
|
|
293
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD } from '../controllers/audit.controllers.js';
|
|
4
|
+
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs } from '../controllers/audit.controllers.js';
|
|
5
5
|
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditRouter = express.Router();
|
|
@@ -39,4 +39,7 @@ auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotA
|
|
|
39
39
|
// audit user wallet
|
|
40
40
|
auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
|
|
41
41
|
auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
|
|
42
|
+
|
|
43
|
+
// audit log
|
|
44
|
+
auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, auditViewLogs );
|
|
42
45
|
export default auditRouter;
|
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid } from '../dtos/traxAudit.dtos.js';
|
|
3
|
+
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
|
|
4
4
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
5
|
-
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save } from '../controllers/traxAudit.controllers.js';
|
|
6
|
-
import { isTraxAuditDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
5
|
+
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
|
|
6
|
+
import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
7
7
|
|
|
8
8
|
export const traxAuditRouter = Router();
|
|
9
9
|
|
|
10
10
|
// Audit Mapping
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
|
|
12
|
+
traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
|
|
13
|
+
traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, save );
|
|
14
|
+
traxAuditRouter.post( '/save-draft', validate( saveDraftValid ), isAllowedSessionHandler, saveDraft );
|
|
15
|
+
traxAuditRouter.get( '/get-drafted-data', validate( getDraftedDataValid ), isAllowedSessionHandler, getDraftedData );
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
// Y/n
|
|
20
19
|
traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
|
|
21
20
|
traxAuditRouter.post( '/get-updated-file', isAllowedSessionHandler, validate( getUpdatedFileValid ), isTraxAuditDocumentExist, getUpdatedFile );
|
|
22
|
-
traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate(
|
|
21
|
+
traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate( saveBinaryValid ), validateBinaryAudit, saveBinary );
|
|
23
22
|
|
|
24
23
|
// metrcis
|
|
24
|
+
traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
|
|
25
25
|
traxAuditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
|
|
26
26
|
traxAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
|
|
27
27
|
traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
|
|
28
28
|
traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
|
|
29
29
|
traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
|
|
30
30
|
traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
|
|
31
|
+
traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValidSchema ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
|
|
31
32
|
|
|
32
33
|
// summary
|
|
33
34
|
|
|
34
35
|
traxAuditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
|
|
35
36
|
traxAuditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
|
|
39
|
-
traxAuditRouter.post( '/save', isAllowedSessionHandler, save );
|
|
40
|
-
traxAuditRouter.post( '/save-draft', isAllowedSessionHandler, saveDraft );
|
|
41
|
-
traxAuditRouter.get( '/get-drafted-data', isAllowedSessionHandler, getDraftedData );
|
|
42
|
-
|
|
43
38
|
export default traxAuditRouter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import auditUserWalletModel from 'tango-api-schema/schema/auditUserWallet.model.js';
|
|
2
|
-
|
|
2
|
+
import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
|
|
3
3
|
|
|
4
4
|
export function createAuditUserWallet( record ) {
|
|
5
5
|
return auditUserWalletModel.create( record );
|
|
@@ -8,3 +8,6 @@ export function createAuditUserWallet( record ) {
|
|
|
8
8
|
export function updateManyAuditUserWallet( query, record ) {
|
|
9
9
|
return auditUserWalletModel.updateMany( query, record, { upsert: true } );
|
|
10
10
|
};
|
|
11
|
+
export function createempDetectionOutput( query, field, option ) {
|
|
12
|
+
return empDetectionOutputModel.updateOne( query, field, option );
|
|
13
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
|
|
3
|
-
export function
|
|
4
|
-
return empDetectionOutputModel.
|
|
3
|
+
export function updateOneEmpDetectionOutput( query, record, upsert ) {
|
|
4
|
+
return empDetectionOutputModel.updateOne( query, record, upsert );
|
|
5
5
|
}
|
|
@@ -5,9 +5,14 @@ export function aggregateStoreEmpDetection( query ) {
|
|
|
5
5
|
return storeEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export function findOneStoreEmpDetection( query ) {
|
|
9
|
+
return storeEmpDetectionModel.findOne( query );
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export function updateOneStoreEmpDetection( query, record ) {
|
|
9
13
|
return storeEmpDetectionModel.updateOne( query, { $set: record } );
|
|
10
14
|
}
|
|
15
|
+
|
|
11
16
|
export function updateManyStoreEmpDetection( query, record ) {
|
|
12
17
|
return storeEmpDetectionModel.updateMany( query, { $set: record }, { upsert: true } );
|
|
13
18
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import userEmpDetectionModel from 'tango-api-schema/schema/userEmpDetection.model.js';
|
|
2
|
+
import { logger } from 'tango-app-api-middleware';
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
export function aggregateUserEmpDetection( query ) {
|
|
6
|
+
logger.info( { seelevt: 'yryruteretwyyyyyyyyyyyyyyyyyyyyyyyyyyyyewe' } );
|
|
5
7
|
return userEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
8
|
}
|
|
7
9
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { checkFileExist, logger } from 'tango-app-api-middleware';
|
|
2
2
|
import { findOneBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
|
|
3
3
|
import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
|
|
4
4
|
import { findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
5
|
+
import { findOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
5
6
|
|
|
6
7
|
export async function validateUserEmpDetection( req, res, next ) {
|
|
7
8
|
try {
|
|
@@ -116,3 +117,48 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
|
|
|
116
117
|
return res.sendError( err, 500 );
|
|
117
118
|
}
|
|
118
119
|
}
|
|
120
|
+
|
|
121
|
+
export async function isuserEmpDocumentExist( req, res, next ) {
|
|
122
|
+
try {
|
|
123
|
+
const inputData = req.body;
|
|
124
|
+
const query={
|
|
125
|
+
storeId: inputData.storeId,
|
|
126
|
+
fileDate: inputData.fileDate,
|
|
127
|
+
moduleType: inputData.moduleType,
|
|
128
|
+
};
|
|
129
|
+
const auditInfo = await findOneStoreEmpDetection( query );
|
|
130
|
+
if ( auditInfo ) {
|
|
131
|
+
const sqs = await findOneTraxAuditData( query, { sqs: 1 } );
|
|
132
|
+
req.sqs = sqs.sqs.Body;
|
|
133
|
+
req.audit = auditInfo;
|
|
134
|
+
return next();
|
|
135
|
+
} else {
|
|
136
|
+
return res.sendError( 'No audited Record', 400 );
|
|
137
|
+
}
|
|
138
|
+
} catch ( error ) {
|
|
139
|
+
const err = error.message || 'Internal Server Error';
|
|
140
|
+
logger.error( { error: error, message: req.body, function: 'isAuditFileExist' } );
|
|
141
|
+
return res.sendError( err, 500 );
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
export async function isMappingAuditInputFolderExist( req, res, next ) {
|
|
147
|
+
try {
|
|
148
|
+
// const inputData = req.method === 'POST' ? req.body : req.query;
|
|
149
|
+
const params={
|
|
150
|
+
Bucket: req.sqs.inputBucketName,
|
|
151
|
+
Key: req.sqs.folderPath.replace( /\/$/, '' ),
|
|
152
|
+
};
|
|
153
|
+
const isExist = await checkFileExist( params );
|
|
154
|
+
if ( isExist ) {
|
|
155
|
+
next();
|
|
156
|
+
} else {
|
|
157
|
+
return res.sendError( `Audit Input folder not available : ${req.sqs.folderPath}`, 400 );
|
|
158
|
+
}
|
|
159
|
+
} catch ( error ) {
|
|
160
|
+
const err = error.message || 'Internal Server Error';
|
|
161
|
+
logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
|
|
162
|
+
return res.sendError( err, 500 );
|
|
163
|
+
}
|
|
164
|
+
}
|