tango-app-api-audit 1.0.57 → 1.0.59
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.59",
|
|
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"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"nodemon": "^3.1.3",
|
|
26
26
|
"swagger-ui-express": "^5.0.1",
|
|
27
27
|
"tango-api-schema": "^2.0.152",
|
|
28
|
-
"tango-app-api-middleware": "^3.1.
|
|
28
|
+
"tango-app-api-middleware": "^3.1.30",
|
|
29
29
|
"winston": "^3.13.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
31
31
|
},
|
|
@@ -533,7 +533,6 @@ export async function getAuditFile( req, res ) {
|
|
|
533
533
|
queueName: inputData.queueName,
|
|
534
534
|
beforeCount: msg.total_count || files.length,
|
|
535
535
|
auditStatus: 'inprogress',
|
|
536
|
-
moduleType: 'traffic',
|
|
537
536
|
fileDateISO: start,
|
|
538
537
|
timeSpent: 0,
|
|
539
538
|
startTime: new Date(),
|
|
@@ -1208,8 +1207,22 @@ export async function save( req, res ) {
|
|
|
1208
1207
|
try {
|
|
1209
1208
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
1210
1209
|
const sqs = JSON.parse( process.env.SQS );
|
|
1211
|
-
|
|
1212
1210
|
const inputData = req.body;
|
|
1211
|
+
let storeAuditData = await findOneStoreAudit( {
|
|
1212
|
+
storeId: inputData.storeId,
|
|
1213
|
+
fileDate: inputData.fileDate,
|
|
1214
|
+
moduleType: inputData.moduleType,
|
|
1215
|
+
zoneName: inputData.zoneName,
|
|
1216
|
+
auditType: inputData.auditType,
|
|
1217
|
+
} );
|
|
1218
|
+
logger.info( { storeAuditData: storeAuditData } );
|
|
1219
|
+
if ( storeAuditData==null ) {
|
|
1220
|
+
logger.error( {
|
|
1221
|
+
error: `No data found: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1222
|
+
type: 'DATABASE_RECORD_NOTFOUND',
|
|
1223
|
+
} );
|
|
1224
|
+
return res.sendError( storeAuditData, 204 );
|
|
1225
|
+
}
|
|
1213
1226
|
const params = {
|
|
1214
1227
|
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1215
1228
|
};
|
|
@@ -1264,12 +1277,12 @@ export async function save( req, res ) {
|
|
|
1264
1277
|
return res.sendError( mappingUpload, 500 );
|
|
1265
1278
|
}
|
|
1266
1279
|
|
|
1267
|
-
let getUserAuditData = await findOneUserAudit( {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
} );
|
|
1272
|
-
const isoDate =
|
|
1280
|
+
// let getUserAuditData = await findOneUserAudit( {
|
|
1281
|
+
// _id: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1282
|
+
// // moduleType: inputData.moduleType,
|
|
1283
|
+
// // zoneName: inputData.zoneName,
|
|
1284
|
+
// } );
|
|
1285
|
+
const isoDate = userAudit?.startTime;
|
|
1273
1286
|
const currentTime = dayjs();
|
|
1274
1287
|
const isoDateTime = dayjs( isoDate );
|
|
1275
1288
|
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
@@ -1294,27 +1307,17 @@ export async function save( req, res ) {
|
|
|
1294
1307
|
|
|
1295
1308
|
let storeConfig = await findOneStore(
|
|
1296
1309
|
{
|
|
1297
|
-
storeId:
|
|
1310
|
+
storeId: userAudit?.storeId,
|
|
1298
1311
|
},
|
|
1299
1312
|
{
|
|
1300
1313
|
auditConfigs: 1,
|
|
1301
1314
|
clientId: 1,
|
|
1302
1315
|
},
|
|
1303
1316
|
);
|
|
1304
|
-
let storeAuditData = await findOneStoreAudit( {
|
|
1305
|
-
storeId: inputData.storeId,
|
|
1306
|
-
fileDate: inputData.fileDate,
|
|
1307
|
-
moduleType: inputData.moduleType,
|
|
1308
|
-
zoneName: inputData.zoneName,
|
|
1309
|
-
auditType: inputData.auditType,
|
|
1310
|
-
} );
|
|
1311
1317
|
|
|
1312
1318
|
let clientData = await findClient( { clientId: storeConfig.clientId } );
|
|
1313
|
-
|
|
1314
|
-
if (
|
|
1315
|
-
( storeAuditData.beforeCount - inputData.customerCount ) /
|
|
1316
|
-
storeAuditData.beforeCount <
|
|
1317
|
-
storeConfig.auditConfigs.ratio &&
|
|
1319
|
+
const ratio = ( ( storeAuditData.beforeCount - inputData.customerCount ) / storeAuditData.beforeCount ) * 100;
|
|
1320
|
+
if ( ratio < storeConfig.auditConfigs.ratio &&
|
|
1318
1321
|
inputData.auditType == 'Audit' &&
|
|
1319
1322
|
inputData.moduleType == 'traffic'
|
|
1320
1323
|
) {
|
|
@@ -1371,7 +1374,7 @@ export async function save( req, res ) {
|
|
|
1371
1374
|
fileDate: inputData.fileDate,
|
|
1372
1375
|
moduleType: inputData.moduleType,
|
|
1373
1376
|
zoneName: inputData.zoneName,
|
|
1374
|
-
auditType: inputData.auditType,
|
|
1377
|
+
// auditType: inputData.auditType,
|
|
1375
1378
|
},
|
|
1376
1379
|
{
|
|
1377
1380
|
status: 'completed',
|
|
@@ -2750,7 +2753,7 @@ export async function reTrigger( req, res ) {
|
|
|
2750
2753
|
}
|
|
2751
2754
|
|
|
2752
2755
|
const storeRecord ={
|
|
2753
|
-
status:
|
|
2756
|
+
status: 'not_assign',
|
|
2754
2757
|
};
|
|
2755
2758
|
|
|
2756
2759
|
await updateOneStoreAudit( query, storeRecord );
|
|
@@ -2810,7 +2813,7 @@ export async function reTrigger( req, res ) {
|
|
|
2810
2813
|
}
|
|
2811
2814
|
|
|
2812
2815
|
const storeRecord ={
|
|
2813
|
-
status:
|
|
2816
|
+
status: 'assigned',
|
|
2814
2817
|
};
|
|
2815
2818
|
|
|
2816
2819
|
await updateOneStoreAudit( query, storeRecord );
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, overViewTableSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema } from '../dtos/audit.dtos.js';
|
|
1
|
+
import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, overViewTableSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema } from '../dtos/audit.dtos.js';
|
|
2
2
|
import j2s from 'joi-to-swagger';
|
|
3
3
|
|
|
4
4
|
export const auditDocs = {
|
|
@@ -466,4 +466,58 @@ export const auditDocs = {
|
|
|
466
466
|
},
|
|
467
467
|
},
|
|
468
468
|
},
|
|
469
|
+
|
|
470
|
+
'/v3/audit/audit-images': {
|
|
471
|
+
get: {
|
|
472
|
+
tags: [ 'Audit Metrics' ],
|
|
473
|
+
description: `View and Download audit images`,
|
|
474
|
+
operationId: 'audit-images',
|
|
475
|
+
parameters: [
|
|
476
|
+
{
|
|
477
|
+
in: 'query',
|
|
478
|
+
name: 'fileDate',
|
|
479
|
+
scema: j2s( auditImageValidSchema ).swagger,
|
|
480
|
+
require: true,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
in: 'query',
|
|
484
|
+
name: 'storeId',
|
|
485
|
+
scema: j2s( auditImageValidSchema ).swagger,
|
|
486
|
+
require: true,
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
in: 'query',
|
|
490
|
+
name: 'imageType',
|
|
491
|
+
scema: j2s( auditImageValidSchema ).swagger,
|
|
492
|
+
require: true,
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
in: 'query',
|
|
496
|
+
name: 'export',
|
|
497
|
+
scema: j2s( auditImageValidSchema ).swagger,
|
|
498
|
+
require: true,
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
in: 'query',
|
|
502
|
+
name: 'moduleType',
|
|
503
|
+
scema: j2s( auditImageValidSchema ).swagger,
|
|
504
|
+
require: true,
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
in: 'query',
|
|
508
|
+
name: 'zoneName',
|
|
509
|
+
scema: j2s( auditImageValidSchema ).swagger,
|
|
510
|
+
require: true,
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
responses: {
|
|
514
|
+
200: { description: 'Successful' },
|
|
515
|
+
401: { description: 'Unauthorized User' },
|
|
516
|
+
422: { description: 'Field Error' },
|
|
517
|
+
500: { description: 'Server Error' },
|
|
518
|
+
204: { description: 'Not Found' },
|
|
519
|
+
},
|
|
520
|
+
|
|
521
|
+
},
|
|
522
|
+
},
|
|
469
523
|
};
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -302,3 +302,19 @@ export const summarySplitSchema = joi.object(
|
|
|
302
302
|
export const summarySplitValid = {
|
|
303
303
|
body: summarySplitSchema,
|
|
304
304
|
};
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
export const auditImageValidSchema = joi.object(
|
|
308
|
+
{
|
|
309
|
+
fileDate: joi.string().required(),
|
|
310
|
+
storeId: joi.string().required(),
|
|
311
|
+
imageType: joi.string().required(),
|
|
312
|
+
export: joi.boolean().required(),
|
|
313
|
+
moduleType: joi.string().required(),
|
|
314
|
+
zoneName: joi.string().required(),
|
|
315
|
+
},
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
export const auditImageValid = {
|
|
319
|
+
query: auditImageValidSchema,
|
|
320
|
+
};
|
|
@@ -2,7 +2,8 @@ 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
4
|
import { auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overViewTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/audit.controllers.js';
|
|
5
|
-
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, overViewTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid } from '../dtos/audit.dtos.js';
|
|
5
|
+
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, overViewTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid } from '../dtos/audit.dtos.js';
|
|
6
|
+
import { auditImages } from '../controllers/auditMetrics.controllers.js';
|
|
6
7
|
|
|
7
8
|
export const auditRouter = express.Router();
|
|
8
9
|
|
|
@@ -27,6 +28,7 @@ auditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( us
|
|
|
27
28
|
auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overViewTableValid ), overViewTable );
|
|
28
29
|
auditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
|
|
29
30
|
auditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
|
|
31
|
+
auditRouter.get( '/audit-images', isAllowedSessionHandler, validate( auditImageValid ), isAuditInputFolderExist, auditImages );
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
// hold
|
|
@@ -213,7 +213,7 @@ export async function getAuditImageData( data ) {
|
|
|
213
213
|
const files = [];
|
|
214
214
|
const fetchData = {
|
|
215
215
|
Bucket: `${bucket.auditInput}`,
|
|
216
|
-
filePath: `${fileDate}/${storeId}/`,
|
|
216
|
+
filePath: `${fileDate}/${storeId}/${data.zoneName}/`,
|
|
217
217
|
};
|
|
218
218
|
const folderPath = await listFileWithoutLimit( fetchData );
|
|
219
219
|
if ( folderPath.statusCode == 404 ) {
|
|
@@ -225,7 +225,7 @@ export async function getAuditImageData( data ) {
|
|
|
225
225
|
if ( auditImages && auditImages?.length > 0 ) {
|
|
226
226
|
for ( let i = 0; i < auditImages.length; i++ ) {
|
|
227
227
|
const img = auditImages[i].Key.split( '/' );
|
|
228
|
-
const image = img[
|
|
228
|
+
const image = img[3].split( '.' );
|
|
229
229
|
const indexes = image[0].split( '_' );
|
|
230
230
|
const params = {
|
|
231
231
|
file_path: auditImages[i].Key,
|
|
@@ -303,7 +303,7 @@ export async function getAuditFilterData( data ) {
|
|
|
303
303
|
const fileDate = data.fileDate;
|
|
304
304
|
const params = {
|
|
305
305
|
Bucket: `${bucket.auditOutput}`,
|
|
306
|
-
Key: `${storeId}/${fileDate}/${bucket.masterJsonFile}`,
|
|
306
|
+
Key: `${storeId}/${data.zoneName}/${fileDate}/${bucket.masterJsonFile}`,
|
|
307
307
|
};
|
|
308
308
|
const mappingFile = await getJsonFileData( params );
|
|
309
309
|
if ( mappingFile.statusCode ) {
|