tango-app-api-audit 1.0.64 → 1.0.67
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/app.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { auditRouter } from './index.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
import { logger } from 'tango-app-api-middleware';
|
|
5
|
+
import { connectdb } from './config/database/database.js';
|
|
6
|
+
import responseMiddleware from './config/response/response.js';
|
|
7
|
+
import errorMiddleware from './config/response/error.js';
|
|
8
|
+
import pkg from 'body-parser';
|
|
9
|
+
import { swaggerConfig } from './config/swagger/swagger.js';
|
|
10
|
+
import swagger from 'swagger-ui-express';
|
|
11
|
+
|
|
12
|
+
const { json, urlencoded } = pkg;
|
|
13
|
+
const env=dotenv.config();
|
|
14
|
+
|
|
15
|
+
const app = express();
|
|
16
|
+
const PORT = process.env.PORT || 3000;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
app.use( json( { limit: '500mb' } ) );
|
|
20
|
+
app.use(
|
|
21
|
+
urlencoded( {
|
|
22
|
+
extended: true,
|
|
23
|
+
} ),
|
|
24
|
+
);
|
|
25
|
+
app.use( responseMiddleware );
|
|
26
|
+
app.use( errorMiddleware );
|
|
27
|
+
if ( env.error ) {
|
|
28
|
+
logger.error( '.env not found' );
|
|
29
|
+
process.exit( 1 );
|
|
30
|
+
}
|
|
31
|
+
app.use( '/api-docs', swagger.serve, swagger.setup( swaggerConfig ) );
|
|
32
|
+
app.use( '/v3/audit', auditRouter );
|
|
33
|
+
|
|
34
|
+
app.listen( PORT, () => {
|
|
35
|
+
logger.info( `server is running on port= ${PORT} ` );
|
|
36
|
+
connectdb();
|
|
37
|
+
} );
|
|
38
|
+
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.67",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "app.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -1293,7 +1293,7 @@ export async function save( req, res ) {
|
|
|
1293
1293
|
// // moduleType: inputData.moduleType,
|
|
1294
1294
|
// // zoneName: inputData.zoneName,
|
|
1295
1295
|
// } );
|
|
1296
|
-
const isoDate = req.
|
|
1296
|
+
const isoDate = req.userAudit?.startTime;
|
|
1297
1297
|
const currentTime = dayjs();
|
|
1298
1298
|
const isoDateTime = dayjs( isoDate );
|
|
1299
1299
|
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
@@ -1318,7 +1318,7 @@ export async function save( req, res ) {
|
|
|
1318
1318
|
|
|
1319
1319
|
let storeConfig = await findOneStore(
|
|
1320
1320
|
{
|
|
1321
|
-
storeId: req.
|
|
1321
|
+
storeId: req.userAudit?.storeId,
|
|
1322
1322
|
},
|
|
1323
1323
|
{
|
|
1324
1324
|
auditConfigs: 1,
|
|
@@ -1326,8 +1326,8 @@ export async function save( req, res ) {
|
|
|
1326
1326
|
},
|
|
1327
1327
|
);
|
|
1328
1328
|
|
|
1329
|
-
let clientData = await findClient( { clientId:
|
|
1330
|
-
const ratio = ( ( storeAuditData.beforeCount - inputData.customerCount ) / storeAuditData.beforeCount )
|
|
1329
|
+
let clientData = await findClient( { clientId: req.userAudit?.clientId } );
|
|
1330
|
+
const ratio = ( ( storeAuditData.beforeCount - inputData.customerCount ) / storeAuditData.beforeCount );
|
|
1331
1331
|
if ( ratio < storeConfig.auditConfigs.ratio &&
|
|
1332
1332
|
inputData.auditType == 'Audit' &&
|
|
1333
1333
|
inputData.moduleType == 'traffic'
|
|
@@ -1336,9 +1336,12 @@ export async function save( req, res ) {
|
|
|
1336
1336
|
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
1337
1337
|
'Reaudit',
|
|
1338
1338
|
);
|
|
1339
|
-
|
|
1339
|
+
const queueName = inputData.moduleType == 'zone' ? clientData[0].auditConfigs.zoneQueueName : clientData[0].auditConfigs.trafficQueueName;
|
|
1340
|
+
if ( !queueName ) {
|
|
1341
|
+
logger.error( { error: 'queueName is undefined', queueName: queueName, moduleType: inputData.moduleType, function: 'save' } );
|
|
1342
|
+
}
|
|
1340
1343
|
const sqsProduceQueue = {
|
|
1341
|
-
QueueUrl: `${sqs.url}${
|
|
1344
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
1342
1345
|
MessageBody: JSON.stringify( {
|
|
1343
1346
|
store_id: inputData.storeId,
|
|
1344
1347
|
audit_type: 'ReAudit',
|
|
@@ -21,13 +21,13 @@ export async function isExistsQueue( req, res, next ) {
|
|
|
21
21
|
export async function validateUserAudit( req, res, next ) {
|
|
22
22
|
try {
|
|
23
23
|
const inputData = req.body;
|
|
24
|
-
const userAuditDetails = findOneUserAudit( { _id: inputData.auditId } );
|
|
24
|
+
const userAuditDetails =await findOneUserAudit( { _id: inputData.auditId } );
|
|
25
25
|
if ( !userAuditDetails ) {
|
|
26
26
|
return res.sendError( 'No Data Available' );
|
|
27
27
|
} else if ( userAuditDetails && userAuditDetails.auditStatus == 'skipped' ) {
|
|
28
28
|
return res.sendError( 'The Audit file Assigned to some one else', 203 );
|
|
29
29
|
}
|
|
30
|
-
req.
|
|
30
|
+
req.userAudit = userAuditDetails;
|
|
31
31
|
next();
|
|
32
32
|
} catch ( error ) {
|
|
33
33
|
const err = error.message || 'Internal Server Error';
|