tango-app-api-audit 1.0.44 → 1.0.46

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.44",
3
+ "version": "1.0.46",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -257,6 +257,7 @@ export async function getAuditFile( req, res ) {
257
257
  queueName: inputData.queueName,
258
258
  beforeCount: reauditImg.length,
259
259
  auditStatus: 'inprogress',
260
+ moduleType: 'traffic',
260
261
  fileDateISO: start,
261
262
  timeSpent: 0,
262
263
  startTime: new Date(),
@@ -377,6 +378,7 @@ export async function getAuditFile( req, res ) {
377
378
  queueName: inputData.queueName,
378
379
  beforeCount: msg.total_count || files.length,
379
380
  auditStatus: 'inprogress',
381
+ moduleType: 'traffic',
380
382
  fileDateISO: start,
381
383
  timeSpent: 0,
382
384
  startTime: new Date(),
@@ -9,13 +9,14 @@ import dayjs from 'dayjs';
9
9
  import { aggregateUserAudit, findOneUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
10
10
  import { aggregateAssignAudit, createAssignAudit } from '../service/assignAudit.service.js';
11
11
  import { createAuditLog, findOneAuditLog } from '../service/auditLog.service.js';
12
- import { getZoneAuditImageData, mapCustomer, mapEmployee, mapJunk, splitB20000, splitE0, splitG20000, zipDownloadImage } from '../validation/audit.validation.js';
12
+ import { mapCustomer, mapEmployee, mapJunk, splitB20000, splitE0, splitG20000, zipDownloadImage } from '../validation/audit.validation.js';
13
13
  import { aggregateClient, findClient, findOneClient } from '../service/client.service.js';
14
14
  import { aggregateAuditClientData } from '../service/auditClientData.service.js';
15
15
  import _ from 'lodash';
16
16
  import mongoose from 'mongoose';
17
17
  import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
18
18
  import { getReauditImg } from './audit.controllers.js';
19
+ import { getZoneAuditFilterData, getZoneAuditImageData } from '../validation/zoneAudit.validation.js';
19
20
 
20
21
  export async function getZoneAuditFile( req, res ) {
21
22
  try {
@@ -1369,7 +1370,7 @@ export async function zoneAuditImages( req, res ) {
1369
1370
 
1370
1371
  case 'AC':
1371
1372
 
1372
- const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
1373
+ const [ filterData, auditImageAC ] = await Promise.all( [ getZoneAuditFilterData( inputData ), getZoneAuditImageData( inputData ) ] );
1373
1374
 
1374
1375
  if ( filterData?.errorCode || auditImageAC?.errorCode ) {
1375
1376
  const error = filterData?.errorMsg || auditImageAC.errorMsg;
@@ -1678,6 +1679,7 @@ export async function reTrigger( req, res ) {
1678
1679
  const query ={
1679
1680
  storeId: inputData.storeId,
1680
1681
  fileDate: inputData.fileDate,
1682
+ zoneName: inputData.zoneName,
1681
1683
  };
1682
1684
  const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
1683
1685
  logger.info( { queueName: getQueueName.auditConfigs.zoneQueueName } );
@@ -1815,3 +1817,14 @@ export async function reTrigger( req, res ) {
1815
1817
  return res.sendError( err, 500 );
1816
1818
  }
1817
1819
  }
1820
+
1821
+ export async function viewLog( req, res ) {
1822
+ try {
1823
+ // const inputData = req.body;
1824
+ // const result = await
1825
+ } catch ( error ) {
1826
+ const err = error.message;
1827
+ logger.error( { error: error, message: req.body, function: 'viewLog' } );
1828
+ return res.sendError( err, 500 );
1829
+ }
1830
+ }
@@ -184,3 +184,14 @@ export const auditImageValidSchema = joi.object(
184
184
  export const auditImageValid = {
185
185
  query: auditImageValidSchema,
186
186
  };
187
+
188
+ export const viewLogSchema = joi.object(
189
+ {
190
+ fileDate: joi.string().required(),
191
+ storeId: joi.string().required(),
192
+ },
193
+ );
194
+
195
+ export const viewLogValid = {
196
+ query: viewLogSchema,
197
+ };
@@ -157,3 +157,15 @@ export const reTriggerValid = {
157
157
  body: reTriggerValidSchema,
158
158
  };
159
159
 
160
+ export const viewLogSchema = joi.object(
161
+ {
162
+ fileDate: joi.string().required(),
163
+ storeId: joi.string().required(),
164
+ zoneName: joi.string().required(),
165
+ },
166
+ );
167
+
168
+ export const viewLogValid = {
169
+ body: viewLogSchema,
170
+ };
171
+
@@ -2,7 +2,7 @@
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
4
  import { auditImages, clientMetrics, overAllAuditSummary, overViewCard, overViewTable, reTrigger, storeMetrics, summarySplit, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
5
- import { auditImageValid, clientMetricsValid, overAllAuditSummaryValid, overViewCardValid, overViewTableValid, reTriggerValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
5
+ import { auditImageValid, clientMetricsValid, overAllAuditSummaryValid, overViewCardValid, overViewTableValid, reTriggerValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, viewLogValid } from '../dtos/auditMetrics.dtos.js';
6
6
  import { isAuditDocumentExist, isAuditInputFolderExist } from '../validation/audit.validation.js';
7
7
 
8
8
  export const auditMetricsRouter = express.Router();
@@ -17,5 +17,6 @@ auditMetricsRouter.post( '/overview-table', isAllowedSessionHandler, validate( o
17
17
  auditMetricsRouter.post( '/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
18
18
  auditMetricsRouter.post( '/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
19
19
  auditMetricsRouter.get( '/audit-images', isAllowedSessionHandler, validate( auditImageValid ), isAuditInputFolderExist, auditImages );
20
+ auditMetricsRouter.post( '/view-log', isAllowedSessionHandler, validate( viewLogValid ), isAuditInputFolderExist, auditImages );
20
21
 
21
22
  export default auditMetricsRouter;
@@ -1,9 +1,10 @@
1
1
  import { Router } from 'express';
2
- import { clientMetricsValid, getDraftedDataValid, getFileValid, reTriggerValid, saveDraftValid, saveValid, workSpaceValid, zoneAuditImageValid } from '../dtos/zoneAudit.dtos.js';
3
- import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, isZoneAuditInputFolderExist, validateUserAudit } from '../validation/audit.validation.js';
2
+ import { clientMetricsValid, getDraftedDataValid, getFileValid, reTriggerValid, saveDraftValid, saveValid, viewLogValid, workSpaceValid, zoneAuditImageValid } from '../dtos/zoneAudit.dtos.js';
3
+ import { isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
4
4
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
5
- import { clientMetrics, getDraftedData, getZoneAuditFile, reTrigger, save, saveDraft, storeMetrics, workSpace, zoneAuditImages } from '../controllers/zoneAudit.controller.js';
5
+ import { clientMetrics, getDraftedData, getZoneAuditFile, reTrigger, save, saveDraft, storeMetrics, viewLog, workSpace, zoneAuditImages } from '../controllers/zoneAudit.controller.js';
6
6
  import { storeMetricsValid } from '../dtos/auditMetrics.dtos.js';
7
+ import { isZoneAuditInputFolderExist, isAuditInputFolderExist, isAuditDocumentExist } from '../validation/zoneAudit.validation.js';
7
8
 
8
9
  export const zoneAuditRouter=Router();
9
10
 
@@ -20,3 +21,4 @@ zoneAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validat
20
21
  zoneAuditRouter.get( '/metrics/audit-images', isAllowedSessionHandler, validate( zoneAuditImageValid ), isZoneAuditInputFolderExist, zoneAuditImages );
21
22
  zoneAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
22
23
  zoneAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
24
+ zoneAuditRouter.post( '/view-log', isAllowedSessionHandler, validate( viewLogValid ), viewLog );
@@ -329,90 +329,4 @@ export async function getAuditFilterData( data ) {
329
329
  }
330
330
  }
331
331
 
332
- // zone
333
- export async function isZoneAuditInputFolderExist( req, res, next ) {
334
- try {
335
- const bucket = JSON.parse( process.env.BUCKET );
336
- const inputData = req.method === 'POST' ? req.body : req.query;
337
- const params={
338
- Bucket: bucket.auditInput,
339
- Key: `${inputData.fileDate}/${inputData.storeId}/${inputData.zoneName}`,
340
- };
341
- const isExist = await checkFileExist( params );
342
- if ( isExist ) {
343
- next();
344
- } else {
345
- return res.sendError( `Audit Input folder not available : ${inputData.fileDate}/${inputData.storeId}`, 400 );
346
- }
347
- } catch ( error ) {
348
- const err = error.message || 'Internal Server Error';
349
- logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
350
- return res.sendError( err, 500 );
351
- }
352
- }
353
-
354
- export async function getZoneAuditImageData( data ) {
355
- try {
356
- const bucket = JSON.parse( process.env.BUCKET );
357
- const storeId = data.storeId;
358
- const fileDate = data.fileDate;
359
- const files = [];
360
- const fetchData = {
361
- Bucket: `${bucket.auditInput}`,
362
- filePath: `${fileDate}/${storeId}/${data.zoneName}/`,
363
- };
364
-
365
- const folderPath = await listFileWithoutLimit( fetchData );
366
- if ( folderPath.statusCode == 404 ) {
367
- return folderPath;
368
- }
369
- const auditImages = folderPath;
370
332
 
371
- if ( data.export==false ) {
372
- if ( auditImages && auditImages?.length > 0 ) {
373
- for ( let i = 0; i < auditImages.length; i++ ) {
374
- const img = auditImages[i].Key.split( '/' );
375
- const image = img[3].split( '.' );
376
- const indexes = image[0].split( '_' );
377
- const params = {
378
- file_path: auditImages[i].Key,
379
- Bucket: fetchData.Bucket,
380
- };
381
- const data = await signedUrl( params );
382
- files.push( {
383
- imgPath: data,
384
- imgName: indexes[1],
385
- imgId: image[0],
386
- img_name: indexes[1],
387
- // imgFile: auditImages[i],
388
- } );
389
- }
390
- return files;
391
- }
392
- } else {
393
- if ( auditImages && auditImages?.length > 0 ) {
394
- for ( let i = 0; i < auditImages.length; i++ ) {
395
- const img = auditImages[i].Key.split( '/' );
396
- const image = img[3].split( '.' );
397
- const indexes = image[0].split( '_' );
398
- const params = {
399
- file_path: auditImages[i].Key,
400
- Bucket: fetchData.Bucket,
401
- };
402
- const data = await signedUrl( params );
403
- files.push( {
404
- imgPath: data,
405
- imgName: indexes[1],
406
- imgId: image[0],
407
- imgFile: auditImages[i],
408
- img_name: indexes[1],
409
- } );
410
- }
411
- return files;
412
- }
413
- }
414
- } catch ( error ) {
415
- logger.error( { error: error, type: 'getAuditImageData' } );
416
- return error;
417
- }
418
- }
@@ -1,4 +1,4 @@
1
- import { checkFileExist } from 'tango-app-api-middleware';
1
+ import { checkFileExist, getJsonFileData, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
2
2
  import { findOneStoreZoneAudit } from '../service/storeZoneAudit.service.js';
3
3
 
4
4
  export async function isAuditDocumentExist( req, res, next ) {
@@ -43,3 +43,125 @@ export async function isAuditInputFolderExist( req, res, next ) {
43
43
  return res.sendError( err, 500 );
44
44
  }
45
45
  }
46
+
47
+ export async function getZoneAuditFilterData( data ) {
48
+ try {
49
+ const bucket = JSON.parse( process.env.BUCKET );
50
+ const storeId = data.storeId;
51
+ const fileDate = data.fileDate;
52
+ const params = {
53
+ Bucket: `${bucket.auditOutput}`,
54
+ Key: `${storeId}/${data.zoneName}/${fileDate}/${bucket.masterJsonFile}`,
55
+ };
56
+ const mappingFile = await getJsonFileData( params );
57
+ if ( mappingFile.statusCode ) {
58
+ return mappingFile;
59
+ } else {
60
+ const mappingData = await JSON.parse( mappingFile.toString( 'utf-8' ) );
61
+ const filterData = await mappingData.person_data.filter(
62
+ ( item ) =>
63
+ item.temp_ids < 20000 &&
64
+ item.temp_ids > 0 &&
65
+ item.person_status === '',
66
+ );
67
+ const finalResult = await filterData.map( ( i ) => {
68
+ return { ...i, img: i.index.concat( '_', i.temp_ids ) };
69
+ } );
70
+ return finalResult;
71
+ }
72
+ } catch ( error ) {
73
+ logger.error( {
74
+ error: error,
75
+ type: 'MAPPING JSON getFilterData',
76
+ function: 'getZoneAuditFilterData',
77
+ } );
78
+ return error;
79
+ }
80
+ }
81
+
82
+ export async function isZoneAuditInputFolderExist( req, res, next ) {
83
+ try {
84
+ const bucket = JSON.parse( process.env.BUCKET );
85
+ const inputData = req.method === 'POST' ? req.body : req.query;
86
+ const params={
87
+ Bucket: bucket.auditInput,
88
+ Key: `${inputData.fileDate}/${inputData.storeId}/${inputData.zoneName}`,
89
+ };
90
+ const isExist = await checkFileExist( params );
91
+ if ( isExist ) {
92
+ next();
93
+ } else {
94
+ return res.sendError( `Audit Input folder not available : ${inputData.fileDate}/${inputData.storeId}`, 400 );
95
+ }
96
+ } catch ( error ) {
97
+ const err = error.message || 'Internal Server Error';
98
+ logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
99
+ return res.sendError( err, 500 );
100
+ }
101
+ }
102
+
103
+ export async function getZoneAuditImageData( data ) {
104
+ try {
105
+ const bucket = JSON.parse( process.env.BUCKET );
106
+ const storeId = data.storeId;
107
+ const fileDate = data.fileDate;
108
+ const files = [];
109
+ const fetchData = {
110
+ Bucket: `${bucket.auditInput}`,
111
+ filePath: `${fileDate}/${storeId}/${data.zoneName}/`,
112
+ };
113
+
114
+ const folderPath = await listFileWithoutLimit( fetchData );
115
+ if ( folderPath.statusCode == 404 ) {
116
+ return folderPath;
117
+ }
118
+ const auditImages = folderPath;
119
+
120
+ if ( data.export==false ) {
121
+ if ( auditImages && auditImages?.length > 0 ) {
122
+ for ( let i = 0; i < auditImages.length; i++ ) {
123
+ const img = auditImages[i].Key.split( '/' );
124
+ const image = img[3].split( '.' );
125
+ const indexes = image[0].split( '_' );
126
+ const params = {
127
+ file_path: auditImages[i].Key,
128
+ Bucket: fetchData.Bucket,
129
+ };
130
+ const data = await signedUrl( params );
131
+ files.push( {
132
+ imgPath: data,
133
+ imgName: indexes[1],
134
+ imgId: image[0],
135
+ img_name: indexes[1],
136
+ // imgFile: auditImages[i],
137
+ } );
138
+ }
139
+ return files;
140
+ }
141
+ } else {
142
+ if ( auditImages && auditImages?.length > 0 ) {
143
+ for ( let i = 0; i < auditImages.length; i++ ) {
144
+ const img = auditImages[i].Key.split( '/' );
145
+ const image = img[3].split( '.' );
146
+ const indexes = image[0].split( '_' );
147
+ const params = {
148
+ file_path: auditImages[i].Key,
149
+ Bucket: fetchData.Bucket,
150
+ };
151
+ const data = await signedUrl( params );
152
+ files.push( {
153
+ imgPath: data,
154
+ imgName: indexes[1],
155
+ imgId: image[0],
156
+ imgFile: auditImages[i],
157
+ img_name: indexes[1],
158
+ } );
159
+ }
160
+ return files;
161
+ }
162
+ }
163
+ } catch ( error ) {
164
+ logger.error( { error: error, type: 'getZoneAuditImageData' } );
165
+ return error;
166
+ }
167
+ }