tango-app-api-audit 1.0.57 → 1.0.58

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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",
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
  };
@@ -1301,13 +1314,6 @@ export async function save( req, res ) {
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
1319
 
@@ -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
  };
@@ -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[2].split( '.' );
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 ) {