tango-app-api-audit 3.6.55 → 3.6.57
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
|
@@ -1993,77 +1993,112 @@ export async function save( req, res ) {
|
|
|
1993
1993
|
inputData.auditType == 'Audit' &&
|
|
1994
1994
|
inputData.moduleType == 'traffic'
|
|
1995
1995
|
) {
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
before_count: storeAuditData.beforeCount,
|
|
2013
|
-
} ),
|
|
2014
|
-
};
|
|
2015
|
-
const sqsQueue = await sendMessageToQueue(
|
|
2016
|
-
sqsProduceQueue.QueueUrl,
|
|
2017
|
-
sqsProduceQueue.MessageBody,
|
|
2018
|
-
);
|
|
2019
|
-
|
|
2020
|
-
if ( sqsQueue.statusCode ) {
|
|
2021
|
-
logger.error( {
|
|
2022
|
-
error: `${sqsQueue}`,
|
|
2023
|
-
type: 'UPLOAD_ERROR',
|
|
2024
|
-
} );
|
|
2025
|
-
return res.sendError( mappingUpload, 500 );
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
await updateOneStoreAudit(
|
|
2029
|
-
{
|
|
2030
|
-
storeId: inputData.storeId,
|
|
2031
|
-
fileDate: inputData.fileDate,
|
|
2032
|
-
moduleType: inputData.moduleType,
|
|
2033
|
-
zoneName: inputData.zoneName,
|
|
2034
|
-
},
|
|
2035
|
-
{
|
|
2036
|
-
status: 'not_assign',
|
|
2037
|
-
afterCount: inputData.customerCount,
|
|
2038
|
-
auditType: 'ReAudit',
|
|
2039
|
-
timeSpent: inputData.timeSpent,
|
|
1996
|
+
// Skip re-pushing the reAudit queue if a reAuditPush log with the
|
|
1997
|
+
// same audit identifiers already exists (prevents duplicate triggers).
|
|
1998
|
+
const reAuditPushQuery = {
|
|
1999
|
+
size: 1,
|
|
2000
|
+
query: {
|
|
2001
|
+
bool: {
|
|
2002
|
+
must: [
|
|
2003
|
+
{ term: { 'logSubType.keyword': 'reAuditPush' } },
|
|
2004
|
+
{ term: { 'logData.fileDate.keyword': req.userAudit?.fileDate } },
|
|
2005
|
+
{ term: { 'logData.auditType.keyword': req.userAudit?.auditType } },
|
|
2006
|
+
{ term: { 'logData.storeId.keyword': req.userAudit?.storeId } },
|
|
2007
|
+
{ term: { 'logData.moduleType.keyword': req.userAudit?.moduleType } },
|
|
2008
|
+
{ term: { 'logData.zoneName.keyword': req.userAudit?.zoneName } },
|
|
2009
|
+
{ term: { 'logData.startTime': req.userAudit?.startTime } },
|
|
2010
|
+
{ term: { 'logData.auditId.keyword': inputData.auditId } },
|
|
2011
|
+
],
|
|
2040
2012
|
},
|
|
2041
|
-
|
|
2013
|
+
},
|
|
2014
|
+
};
|
|
2015
|
+
const existingReAuditPush = await getOpenSearchData( openSearch.auditLog, reAuditPushQuery );
|
|
2016
|
+
const reAuditPushExists = existingReAuditPush?.body?.hits?.total?.value || 0;
|
|
2042
2017
|
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
logSubType: 'reAuditPush',
|
|
2048
|
-
logData: {
|
|
2018
|
+
if ( reAuditPushExists ) {
|
|
2019
|
+
logger.info( {
|
|
2020
|
+
message: 'reAuditPush already exists, skipping queue push',
|
|
2021
|
+
storeId: req.userAudit?.storeId,
|
|
2049
2022
|
fileDate: req.userAudit?.fileDate,
|
|
2050
2023
|
auditType: req.userAudit?.auditType,
|
|
2051
|
-
storeId: req.userAudit?.storeId,
|
|
2052
2024
|
moduleType: req.userAudit?.moduleType,
|
|
2053
2025
|
zoneName: req.userAudit?.zoneName,
|
|
2054
|
-
queueName: req.userAudit?.queueName,
|
|
2055
|
-
clientId: req.userAudit?.clientId,
|
|
2056
|
-
beforeCount: req.userAudit?.beforeCount,
|
|
2057
|
-
afterCount: inputData.customerCount,
|
|
2058
2026
|
startTime: req.userAudit?.startTime,
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2027
|
+
function: 'save',
|
|
2028
|
+
} );
|
|
2029
|
+
} else {
|
|
2030
|
+
logger.info(
|
|
2031
|
+
`Hit in ReAudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
2032
|
+
'ReAudit',
|
|
2033
|
+
);
|
|
2034
|
+
const queueName = inputData.moduleType == 'zone' ? clientData[0].auditConfigs.zoneQueueName : clientData[0].auditConfigs.trafficQueueName;
|
|
2035
|
+
if ( !queueName ) {
|
|
2036
|
+
logger.error( { error: 'queueName is undefined', queueName: queueName, moduleType: inputData.moduleType, function: 'save' } );
|
|
2037
|
+
}
|
|
2038
|
+
const sqsProduceQueue = {
|
|
2039
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
2040
|
+
MessageBody: JSON.stringify( {
|
|
2041
|
+
store_id: inputData.storeId,
|
|
2042
|
+
zone_id: inputData.zoneName,
|
|
2043
|
+
audit_type: 'ReAudit',
|
|
2044
|
+
curr_date: inputData.fileDate,
|
|
2045
|
+
total_count: inputData.customerCount,
|
|
2046
|
+
before_count: storeAuditData.beforeCount,
|
|
2047
|
+
} ),
|
|
2048
|
+
};
|
|
2049
|
+
const sqsQueue = await sendMessageToQueue(
|
|
2050
|
+
sqsProduceQueue.QueueUrl,
|
|
2051
|
+
sqsProduceQueue.MessageBody,
|
|
2052
|
+
);
|
|
2065
2053
|
|
|
2066
|
-
|
|
2054
|
+
if ( sqsQueue.statusCode ) {
|
|
2055
|
+
logger.error( {
|
|
2056
|
+
error: `${sqsQueue}`,
|
|
2057
|
+
type: 'UPLOAD_ERROR',
|
|
2058
|
+
} );
|
|
2059
|
+
return res.sendError( mappingUpload, 500 );
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
await updateOneStoreAudit(
|
|
2063
|
+
{
|
|
2064
|
+
storeId: inputData.storeId,
|
|
2065
|
+
fileDate: inputData.fileDate,
|
|
2066
|
+
moduleType: inputData.moduleType,
|
|
2067
|
+
zoneName: inputData.zoneName,
|
|
2068
|
+
},
|
|
2069
|
+
{
|
|
2070
|
+
status: 'not_assign',
|
|
2071
|
+
afterCount: inputData.customerCount,
|
|
2072
|
+
auditType: 'ReAudit',
|
|
2073
|
+
timeSpent: inputData.timeSpent,
|
|
2074
|
+
},
|
|
2075
|
+
);
|
|
2076
|
+
|
|
2077
|
+
const logData = {
|
|
2078
|
+
userId: req.user._id,
|
|
2079
|
+
userName: req.user.userName,
|
|
2080
|
+
logType: 'audit',
|
|
2081
|
+
logSubType: 'reAuditPush',
|
|
2082
|
+
logData: {
|
|
2083
|
+
fileDate: req.userAudit?.fileDate,
|
|
2084
|
+
auditType: req.userAudit?.auditType,
|
|
2085
|
+
storeId: req.userAudit?.storeId,
|
|
2086
|
+
moduleType: req.userAudit?.moduleType,
|
|
2087
|
+
zoneName: req.userAudit?.zoneName,
|
|
2088
|
+
queueName: req.userAudit?.queueName,
|
|
2089
|
+
clientId: req.userAudit?.clientId,
|
|
2090
|
+
beforeCount: req.userAudit?.beforeCount,
|
|
2091
|
+
afterCount: inputData.customerCount,
|
|
2092
|
+
startTime: req.userAudit?.startTime,
|
|
2093
|
+
endTime: Date.now(),
|
|
2094
|
+
timeSpent: inputData.timeSpent,
|
|
2095
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
2096
|
+
},
|
|
2097
|
+
createdAt: Date.now(),
|
|
2098
|
+
};
|
|
2099
|
+
|
|
2100
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
2101
|
+
}
|
|
2067
2102
|
} else {
|
|
2068
2103
|
/* openSearch logs start*/
|
|
2069
2104
|
let id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.email}_${Date.now()}`;
|
|
@@ -3751,7 +3786,7 @@ export async function reTrigger( req, res ) {
|
|
|
3751
3786
|
}
|
|
3752
3787
|
break;
|
|
3753
3788
|
case 'user':
|
|
3754
|
-
|
|
3789
|
+
if ( req.audit.status === 'not_assign' ) {
|
|
3755
3790
|
await releaseReTriggerLock( lockKey );
|
|
3756
3791
|
return res.sendError( 'This store has already assigned to the user', 400 );
|
|
3757
3792
|
}
|
|
@@ -47,9 +47,10 @@ export async function validateUserAudit( req, res, next ) {
|
|
|
47
47
|
return res.sendError( 'No Data Available' );
|
|
48
48
|
} else if ( userAuditDetails && userAuditDetails.auditStatus == 'skipped' ) {
|
|
49
49
|
return res.sendError( 'The Audit file Assigned to some one else', 203 );
|
|
50
|
+
} else {
|
|
51
|
+
req.userAudit = userAuditDetails;
|
|
52
|
+
next();
|
|
50
53
|
}
|
|
51
|
-
req.userAudit = userAuditDetails;
|
|
52
|
-
next();
|
|
53
54
|
} catch ( error ) {
|
|
54
55
|
const err = error.message || 'Internal Server Error';
|
|
55
56
|
logger.error( { error: error, message: req.query, function: 'validateUserAudit' } );
|