tango-app-api-audit 3.3.0-alpha.5 → 3.3.0-alpha.7
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 +38 -0
- package/package.json +3 -3
- package/src/controllers/audit.controllers.js +23 -11
- package/src/validation/audit.validation.js +9 -8
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": "3.3.0-alpha.
|
|
3
|
+
"version": "3.3.0-alpha.7",
|
|
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"
|
|
@@ -337,7 +337,7 @@ export async function getAuditFile( req, res ) {
|
|
|
337
337
|
logType: 'audit',
|
|
338
338
|
logSubType: 'auditStart',
|
|
339
339
|
logData: {
|
|
340
|
-
|
|
340
|
+
fileDate: userDetails[0].fileDate,
|
|
341
341
|
auditType: userDetails[0].auditType,
|
|
342
342
|
storeId: userDetails[0].storeId,
|
|
343
343
|
clientName: log.queueName,
|
|
@@ -345,9 +345,10 @@ export async function getAuditFile( req, res ) {
|
|
|
345
345
|
moduleType: userDetails[0].moduleType,
|
|
346
346
|
zoneName: userDetails[0].zoneName,
|
|
347
347
|
},
|
|
348
|
+
createdAt: new Date(),
|
|
348
349
|
};
|
|
349
350
|
logger.info( { logData: logData } );
|
|
350
|
-
await insertOpenSearchData( openSearch.
|
|
351
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
351
352
|
}
|
|
352
353
|
const storeQuery = {
|
|
353
354
|
storeId: userDetails[0].storeId,
|
|
@@ -446,8 +447,9 @@ export async function getAuditFile( req, res ) {
|
|
|
446
447
|
zoneName: msg.zone_id,
|
|
447
448
|
moduleType: inputData.moduleType,
|
|
448
449
|
},
|
|
450
|
+
createdAt: new Date(),
|
|
449
451
|
};
|
|
450
|
-
await insertOpenSearchData( openSearch.
|
|
452
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
451
453
|
}
|
|
452
454
|
|
|
453
455
|
const storeQuery = {
|
|
@@ -598,8 +600,9 @@ export async function getAuditFile( req, res ) {
|
|
|
598
600
|
zoneName: msg.zone_id,
|
|
599
601
|
moduleType: inputData.moduleType,
|
|
600
602
|
},
|
|
603
|
+
createdAt: new Date(),
|
|
601
604
|
};
|
|
602
|
-
await insertOpenSearchData( openSearch.
|
|
605
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
603
606
|
}
|
|
604
607
|
logger.info( { storeInfo: storeInfo } );
|
|
605
608
|
return res.sendSuccess( {
|
|
@@ -714,8 +717,6 @@ export async function getAuditImage( msg ) {
|
|
|
714
717
|
|
|
715
718
|
export const getReauditImg = async ( filter, image ) => {
|
|
716
719
|
const chunkedMappingData = await chunkArray( image, 10 );
|
|
717
|
-
logger.info( { chunkedMappingData: chunkedMappingData, level: 5 } );
|
|
718
|
-
|
|
719
720
|
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
720
721
|
return mapFunction( chunk, filter );
|
|
721
722
|
} );
|
|
@@ -1160,6 +1161,7 @@ export async function saveDraft( req, res ) {
|
|
|
1160
1161
|
logType: 'audit',
|
|
1161
1162
|
logSubType: 'auditDraft',
|
|
1162
1163
|
logData: {
|
|
1164
|
+
fileDate: insertData.fileDate,
|
|
1163
1165
|
auditType: inputData.auditType,
|
|
1164
1166
|
storeId: inputData.storeId,
|
|
1165
1167
|
clientName: inputData.queueName,
|
|
@@ -1169,8 +1171,9 @@ export async function saveDraft( req, res ) {
|
|
|
1169
1171
|
moduleType: inputData.moduleType,
|
|
1170
1172
|
zoneName: inputData.zoneName,
|
|
1171
1173
|
},
|
|
1174
|
+
createdAt: new Date(),
|
|
1172
1175
|
};
|
|
1173
|
-
await insertOpenSearchData( openSearch.
|
|
1176
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1174
1177
|
}
|
|
1175
1178
|
await createAuditLog( inputData );
|
|
1176
1179
|
await updateOneUserAudit( userQuery, userRecord );
|
|
@@ -2789,8 +2792,9 @@ export async function reTrigger( req, res ) {
|
|
|
2789
2792
|
triggerId: req.user._id,
|
|
2790
2793
|
triggerType: inputData.triggerType,
|
|
2791
2794
|
},
|
|
2795
|
+
createdAt: new Date(),
|
|
2792
2796
|
};
|
|
2793
|
-
await insertOpenSearchData( openSearch.
|
|
2797
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
2794
2798
|
}
|
|
2795
2799
|
break;
|
|
2796
2800
|
case 'user':
|
|
@@ -2849,8 +2853,9 @@ export async function reTrigger( req, res ) {
|
|
|
2849
2853
|
triggerId: req.user._id,
|
|
2850
2854
|
triggerType: inputData.triggerType,
|
|
2851
2855
|
},
|
|
2856
|
+
createdAt: new Date(),
|
|
2852
2857
|
};
|
|
2853
|
-
await insertOpenSearchData( openSearch.
|
|
2858
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
2854
2859
|
}
|
|
2855
2860
|
|
|
2856
2861
|
return res.sendSuccess( { result: 'The File has been Re Trigger Succesfully' } );
|
|
@@ -3060,10 +3065,13 @@ export async function auditImages( req, res ) {
|
|
|
3060
3065
|
case 'BC':
|
|
3061
3066
|
const auditImageBC = await getAuditImageData( inputData );
|
|
3062
3067
|
if ( auditImageBC?.errorCode ) {
|
|
3063
|
-
const error = auditImageBC?.
|
|
3068
|
+
const error = auditImageBC?.error || 'Internal Server Error- get BC from Bucket';
|
|
3064
3069
|
const code = auditImageBC?.errorCode;
|
|
3065
3070
|
return res.sendError( { error: error }, code );
|
|
3066
3071
|
}
|
|
3072
|
+
if ( auditImageBC?.length == 0 ) {
|
|
3073
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3074
|
+
}
|
|
3067
3075
|
|
|
3068
3076
|
if ( inputData.export==true ) {
|
|
3069
3077
|
auditImageDownload= await zipDownloadImage( auditImageBC );
|
|
@@ -3083,12 +3091,16 @@ export async function auditImages( req, res ) {
|
|
|
3083
3091
|
const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
|
|
3084
3092
|
|
|
3085
3093
|
if ( filterData?.errorCode || auditImageAC?.errorCode ) {
|
|
3086
|
-
const error = filterData?.
|
|
3094
|
+
const error = ( filterData?.error || auditImageAC.error ) || 'Internal Server Error- get AC from Bucket';
|
|
3087
3095
|
const code = filterData?.errorCode || auditImageAC.errorCode;
|
|
3088
3096
|
return res.sendError( { error: error }, code );
|
|
3089
3097
|
}
|
|
3090
3098
|
|
|
3091
3099
|
const reauditImg = await getReauditImg( filterData, auditImageAC );
|
|
3100
|
+
logger.info( { reauditImg: reauditImg } );
|
|
3101
|
+
if ( reauditImg?.length == 0 ) {
|
|
3102
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3103
|
+
}
|
|
3092
3104
|
|
|
3093
3105
|
logger.info( { auditImageAC: auditImageAC, filterData: filterData, reauditImg: reauditImg } );
|
|
3094
3106
|
if ( inputData.export==true ) {
|
|
@@ -212,9 +212,10 @@ export async function getAuditImageData( data ) {
|
|
|
212
212
|
const fileDate = data.fileDate;
|
|
213
213
|
const files = [];
|
|
214
214
|
const fetchData = {
|
|
215
|
-
Bucket: `${bucket.
|
|
215
|
+
Bucket: `${bucket.auditInput}`,
|
|
216
216
|
filePath: `${fileDate}/${storeId}/${data.zoneName}/`,
|
|
217
217
|
};
|
|
218
|
+
|
|
218
219
|
const folderPath = await listFileWithoutLimit( fetchData );
|
|
219
220
|
if ( folderPath.statusCode == 404 ) {
|
|
220
221
|
return folderPath;
|
|
@@ -233,11 +234,10 @@ export async function getAuditImageData( data ) {
|
|
|
233
234
|
};
|
|
234
235
|
const data = await signedUrl( params );
|
|
235
236
|
files.push( {
|
|
236
|
-
|
|
237
|
-
imgName: indexes[1],
|
|
238
|
-
imgId: image[0],
|
|
237
|
+
img_path: data,
|
|
239
238
|
img_name: indexes[1],
|
|
240
|
-
|
|
239
|
+
img_id: image[0],
|
|
240
|
+
imgFile: auditImages[i],
|
|
241
241
|
} );
|
|
242
242
|
}
|
|
243
243
|
return files;
|
|
@@ -254,9 +254,8 @@ export async function getAuditImageData( data ) {
|
|
|
254
254
|
};
|
|
255
255
|
const data = await signedUrl( params );
|
|
256
256
|
files.push( {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
imgId: image[0],
|
|
257
|
+
img_path: data,
|
|
258
|
+
img_id: image[0],
|
|
260
259
|
imgFile: auditImages[i],
|
|
261
260
|
img_name: indexes[1],
|
|
262
261
|
} );
|
|
@@ -272,6 +271,7 @@ export async function getAuditImageData( data ) {
|
|
|
272
271
|
|
|
273
272
|
export async function zipDownloadImage( data ) {
|
|
274
273
|
try {
|
|
274
|
+
logger.info( { zipDownloadImage: data } );
|
|
275
275
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
276
276
|
const zip = new AdmZip();
|
|
277
277
|
const split = await chunkArray( data, 10 );
|
|
@@ -281,6 +281,7 @@ export async function zipDownloadImage( data ) {
|
|
|
281
281
|
Bucket: `${bucket.auditInput}`,
|
|
282
282
|
Key: chunk[i].imgFile.Key,
|
|
283
283
|
};
|
|
284
|
+
logger.info( { params: params } );
|
|
284
285
|
const fileBuffer = await getObject( params );
|
|
285
286
|
zip.addFile( chunk[i].imgFile.Key, fileBuffer.Body );
|
|
286
287
|
}
|