tango-app-api-audit 3.4.3-alpha.6 → 3.4.3-alpha.8
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 +29 -23
- package/src/controllers/traxAudit.controllers.js +218 -9
- package/src/docs/traxAudit.docs.js +23 -1
- package/src/dtos/traxAudit.dtos.js +12 -0
- package/src/routes/traxAudit.routes.js +4 -3
- package/src/service/storeEmpDetection.service.js +5 -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,
|
|
@@ -4304,30 +4305,35 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4304
4305
|
|
|
4305
4306
|
export async function auditViewLogs( req, res ) {
|
|
4306
4307
|
try {
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4308
|
+
const inputData = req.query;
|
|
4309
|
+
const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4310
|
+
let downTimeQuery = {
|
|
4311
|
+
'size': 100,
|
|
4312
|
+
'query': {
|
|
4313
|
+
'bool': {
|
|
4314
|
+
'must': [
|
|
4315
|
+
{
|
|
4316
|
+
'term': {
|
|
4317
|
+
'doc.logData.fileDate.keyword': dayjs( inputData.fileDate ).format( 'DD-MM-YYYY' ),
|
|
4318
|
+
},
|
|
4319
|
+
},
|
|
4320
|
+
{
|
|
4321
|
+
'term': {
|
|
4322
|
+
'doc.logData.storeId.keyword': inputData.storeId,
|
|
4323
|
+
},
|
|
4324
|
+
},
|
|
4325
|
+
{
|
|
4326
|
+
'term': {
|
|
4327
|
+
'doc.logData.moduleType.keyword': inputData.moduleType,
|
|
4328
|
+
},
|
|
4329
|
+
},
|
|
4330
|
+
],
|
|
4325
4331
|
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4332
|
+
},
|
|
4333
|
+
},
|
|
4334
|
+
};
|
|
4335
|
+
const downtime = await getOpenSearchData( parsedOpenSearch.auditLog, downTimeQuery );
|
|
4336
|
+
return res.sendSuccess( downtime );
|
|
4331
4337
|
} catch ( err ) {
|
|
4332
4338
|
|
|
4333
4339
|
}
|
|
@@ -4,11 +4,11 @@ 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
10
|
import { aggregateStoreEmpDetection, updateManyStoreEmpDetection, updateOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
|
|
11
|
-
import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.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
14
|
import { findOneAuditLog, createAuditLog,
|
|
@@ -1922,6 +1922,125 @@ export async function clientMetrics( req, res ) {
|
|
|
1922
1922
|
},
|
|
1923
1923
|
];
|
|
1924
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
|
+
|
|
1925
2044
|
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
1926
2045
|
query.push(
|
|
1927
2046
|
{
|
|
@@ -1953,7 +2072,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1953
2072
|
);
|
|
1954
2073
|
}
|
|
1955
2074
|
|
|
1956
|
-
const count = await aggregateTraxAuditData( query );
|
|
2075
|
+
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
1957
2076
|
logger.info( { count: count } );
|
|
1958
2077
|
if ( count.length == 0 ) {
|
|
1959
2078
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -1986,7 +2105,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1986
2105
|
}
|
|
1987
2106
|
|
|
1988
2107
|
logger.info( { query: query } );
|
|
1989
|
-
const result = await aggregateTraxAuditData( query );
|
|
2108
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
1990
2109
|
if ( result.length == 0 ) {
|
|
1991
2110
|
return res.sendError( 'No Data Found', 204 );
|
|
1992
2111
|
}
|
|
@@ -2429,8 +2548,10 @@ export async function storeMetrics( req, res ) {
|
|
|
2429
2548
|
},
|
|
2430
2549
|
);
|
|
2431
2550
|
}
|
|
2551
|
+
logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
|
|
2432
2552
|
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2433
2553
|
|
|
2554
|
+
|
|
2434
2555
|
if ( count.length == 0 ) {
|
|
2435
2556
|
return res.sendError( 'No data Found', 204 );
|
|
2436
2557
|
}
|
|
@@ -2444,7 +2565,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2444
2565
|
} else {
|
|
2445
2566
|
query.push( { $limit: 10000 } );
|
|
2446
2567
|
}
|
|
2447
|
-
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await
|
|
2568
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2448
2569
|
if ( inputData.isExport ) {
|
|
2449
2570
|
const exportdata = [];
|
|
2450
2571
|
result.forEach( ( element ) => {
|
|
@@ -3280,7 +3401,7 @@ export async function summarySplit( req, res ) {
|
|
|
3280
3401
|
},
|
|
3281
3402
|
},
|
|
3282
3403
|
];
|
|
3283
|
-
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await
|
|
3404
|
+
const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3284
3405
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3285
3406
|
result[0].totalCount = totalCount[0]?.total;
|
|
3286
3407
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3840,7 +3961,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3840
3961
|
userId: req.user._id,
|
|
3841
3962
|
storeId: msg.storeId,
|
|
3842
3963
|
clientId: msg.storeId.split( '-' )[0],
|
|
3843
|
-
auditType: 'Audit',
|
|
3964
|
+
auditType: msg.auditType || 'Audit',
|
|
3844
3965
|
fileDate: msg.fileDate,
|
|
3845
3966
|
inputBucketName: msg.inputBucketName,
|
|
3846
3967
|
folderPath: msg.folderPath,
|
|
@@ -3861,7 +3982,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3861
3982
|
userId: req.user._id,
|
|
3862
3983
|
storeId: msg.storeId,
|
|
3863
3984
|
clientId: msg.storeId.split( '-' )[0],
|
|
3864
|
-
auditType: 'Audit',
|
|
3985
|
+
auditType: msg.auditType || 'Audit',
|
|
3865
3986
|
fileDate: msg.fileDate,
|
|
3866
3987
|
folderPath: msg.folderPath,
|
|
3867
3988
|
inputBucketName: msg.inputBucketName,
|
|
@@ -3924,7 +4045,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3924
4045
|
queueName: inputData.queueName,
|
|
3925
4046
|
storeId: storeId,
|
|
3926
4047
|
fileDate: fileDate,
|
|
3927
|
-
auditType: 'Audit',
|
|
4048
|
+
auditType: msg.auditType || 'Audit',
|
|
3928
4049
|
auditId: insertData._id,
|
|
3929
4050
|
userId: insertData.userId,
|
|
3930
4051
|
moduleType: inputData.moduleType,
|
|
@@ -4050,6 +4171,8 @@ export async function getDraftedData( req, res ) {
|
|
|
4050
4171
|
export async function save( req, res ) {
|
|
4051
4172
|
try {
|
|
4052
4173
|
const inputData = req.body;
|
|
4174
|
+
const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
|
|
4175
|
+
inputData.clientId = getUserAuditData.clientId;
|
|
4053
4176
|
const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
|
|
4054
4177
|
const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
|
|
4055
4178
|
if ( data ) {
|
|
@@ -4069,3 +4192,89 @@ export async function save( req, res ) {
|
|
|
4069
4192
|
return res.sendError( err, 500 );
|
|
4070
4193
|
}
|
|
4071
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, saveBinarySchema, saveDraftSchema, getDraftedDataSchema } 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
|
|
|
@@ -403,4 +403,26 @@ export const traxAuditDocs = {
|
|
|
403
403
|
},
|
|
404
404
|
},
|
|
405
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
|
+
},
|
|
406
428
|
};
|
|
@@ -279,3 +279,15 @@ export const saveSchema = joi.object( {
|
|
|
279
279
|
export const saveValid = {
|
|
280
280
|
body: saveSchema,
|
|
281
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,9 +1,9 @@
|
|
|
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, saveBinaryValid, getDraftedDataValid, saveDraftValid } 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
|
|
|
@@ -28,6 +28,7 @@ traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validat
|
|
|
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
|
|
|
@@ -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,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
|
+
}
|