tango-app-api-audit 3.3.0-alpha.2 → 3.3.0-alpha.21

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.
@@ -1,4 +1,4 @@
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';
1
+ import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema } from '../dtos/audit.dtos.js';
2
2
  import j2s from 'joi-to-swagger';
3
3
 
4
4
  export const auditDocs = {
@@ -170,6 +170,24 @@ export const auditDocs = {
170
170
  in: 'query',
171
171
  name: 'storeId',
172
172
  scema: j2s( getDraftedDataSchema ).swagger,
173
+ require: true,
174
+ },
175
+ {
176
+ in: 'query',
177
+ name: 'moduleType',
178
+ scema: j2s( getDraftedDataSchema ).swagger,
179
+ require: true,
180
+ },
181
+ {
182
+ in: 'query',
183
+ name: 'zoneName',
184
+ scema: j2s( getDraftedDataSchema ).swagger,
185
+ require: true,
186
+ },
187
+ {
188
+ in: 'query',
189
+ name: 'userId',
190
+ scema: j2s( getDraftedDataSchema ).swagger,
173
191
  require: false,
174
192
  },
175
193
  ],
@@ -205,54 +223,17 @@ export const auditDocs = {
205
223
  },
206
224
  },
207
225
  '/v3/audit/work-space': {
208
- get: {
226
+ post: {
209
227
  tags: [ 'Audit Mapping' ],
210
228
  description: 'queue wise info of audit files ',
211
229
  operationId: 'work-space',
212
- parameters: [
213
- {
214
- in: 'query',
215
- name: 'moduleType',
216
- scema: j2s( workSpaceSchema ).swagger,
217
- require: true,
218
- },
219
- {
220
- in: 'query',
221
- name: 'searchValue',
222
- scema: j2s( workSpaceSchema ).swagger,
223
- require: false,
224
- },
225
- {
226
- in: 'query',
227
- name: 'offset',
228
- scema: j2s( workSpaceSchema ).swagger,
229
- require: false,
230
- },
231
- {
232
- in: 'query',
233
- name: 'limit',
234
- scema: j2s( workSpaceSchema ).swagger,
235
- require: false,
236
- },
237
- {
238
- in: 'query',
239
- name: 'isExport',
240
- scema: j2s( workSpaceSchema ).swagger,
241
- require: false,
242
- },
243
- {
244
- in: 'query',
245
- name: 'sortColumnName',
246
- scema: j2s( workSpaceSchema ).swagger,
247
- require: false,
248
- },
249
- {
250
- in: 'query',
251
- name: 'sortBy',
252
- scema: j2s( workSpaceSchema ).swagger,
253
- require: false,
230
+ requestBody: {
231
+ content: {
232
+ 'application/json': {
233
+ schema: j2s( workSpaceSchema ).swagger,
234
+ },
254
235
  },
255
- ],
236
+ },
256
237
  responses: {
257
238
  200: { description: 'Successful' },
258
239
  401: { description: 'Unauthorized User' },
@@ -353,6 +334,29 @@ export const auditDocs = {
353
334
  },
354
335
  },
355
336
  },
337
+ '/v3/audit/metrics/pending-summary-table': {
338
+ post: {
339
+ tags: [ 'Audit Metrics' ],
340
+ description: `Get overall user taken data with some filters `,
341
+ operationId: 'metrics/pending-summary-table',
342
+ parameters: {},
343
+ requestBody: {
344
+ content: {
345
+ 'application/json': {
346
+ schema: j2s( pendingSummaryTableSchema ).swagger,
347
+ },
348
+ },
349
+ },
350
+ responses: {
351
+ 200: { description: 'Successful' },
352
+ 401: { description: 'Unauthorized User' },
353
+ 422: { description: 'Field Error' },
354
+ 500: { description: 'Server Error' },
355
+ 204: { description: 'Not Found' },
356
+ },
357
+ },
358
+ },
359
+
356
360
  '/v3/audit/metrics/overview-table': {
357
361
  post: {
358
362
  tags: [ 'Audit Metrics' ],
@@ -362,7 +366,7 @@ export const auditDocs = {
362
366
  requestBody: {
363
367
  content: {
364
368
  'application/json': {
365
- schema: j2s( overViewTableSchema ).swagger,
369
+ schema: j2s( overviewTableSchema ).swagger,
366
370
  },
367
371
  },
368
372
  },
@@ -520,4 +524,18 @@ export const auditDocs = {
520
524
 
521
525
  },
522
526
  },
527
+ '/v3/audit/total-not-assigned-count': {
528
+ get: {
529
+ tags: [ 'Audit Mapping' ],
530
+ description: 'Get total Not Assigned Count',
531
+ operationId: 'clients',
532
+ responses: {
533
+ 200: { description: 'Successful' },
534
+ 401: { description: 'Unauthorized User' },
535
+ 422: { description: 'Field Error' },
536
+ 500: { description: 'Server Error' },
537
+ 204: { description: 'Not Found' },
538
+ },
539
+ },
540
+ },
523
541
  };
@@ -125,6 +125,7 @@ export const workSpaceSchema = joi.object(
125
125
  {
126
126
  searchValue: joi.string().optional().allow( '' ),
127
127
  moduleType: joi.string().required(),
128
+ clientId: joi.array().optional(),
128
129
  offset: joi.number().optional(),
129
130
  limit: joi.number().optional(),
130
131
  isExport: joi.boolean().optional(),
@@ -134,7 +135,7 @@ export const workSpaceSchema = joi.object(
134
135
  );
135
136
 
136
137
  export const workSpaceValid = {
137
- query: workSpaceSchema,
138
+ body: workSpaceSchema,
138
139
  };
139
140
 
140
141
  /* < -- *** Audit Metrics *** --> */
@@ -145,6 +146,7 @@ export const userAuditHistorySchema = joi.object(
145
146
  fromDate: joi.string().required(),
146
147
  toDate: joi.string().required(),
147
148
  dateType: joi.string().required(),
149
+ clientId: joi.array().optional(),
148
150
  filterByStoreId: joi.array().required(),
149
151
  filterByModuleType: joi.array().optional(),
150
152
  filterByAuditType: joi.array().optional(),
@@ -227,7 +229,7 @@ export const userMetricsValid = {
227
229
  body: userMetricsSchema,
228
230
  };
229
231
 
230
- export const overViewTableSchema = joi.object(
232
+ export const pendingSummaryTableSchema = joi.object(
231
233
  {
232
234
  fromDate: joi.string().required(),
233
235
  toDate: joi.string().required(),
@@ -244,8 +246,29 @@ export const overViewTableSchema = joi.object(
244
246
  },
245
247
  );
246
248
 
247
- export const overViewTableValid = {
248
- body: overViewTableSchema,
249
+ export const pendingSummaryTableValid = {
250
+ body: pendingSummaryTableSchema,
251
+ };
252
+
253
+ export const overviewTableSchema = joi.object(
254
+ {
255
+ fromDate: joi.string().required(),
256
+ toDate: joi.string().required(),
257
+ clientId: joi.array().optional(),
258
+ limit: joi.number().optional(),
259
+ offset: joi.number().optional(),
260
+ searchValue: joi.string().optional().allow( '' ),
261
+ filterByStatus: joi.array().optional(),
262
+ filterByModuleType: joi.array().optional(),
263
+ filterByAuditType: joi.array().optional(),
264
+ sortColumnName: joi.string().optional(),
265
+ sortBy: joi.number().optional(),
266
+ isExport: joi.boolean().optional(),
267
+ },
268
+ );
269
+
270
+ export const overviewTableValid= {
271
+ body: overviewTableSchema,
249
272
  };
250
273
 
251
274
  export const overAllAuditSummarySchema = joi.object(
@@ -296,6 +319,7 @@ export const summarySplitSchema = joi.object(
296
319
  fromDate: joi.string().required(),
297
320
  toDate: joi.string().required(),
298
321
  clientId: joi.array().optional(),
322
+ moduleType: joi.array().optional(),
299
323
  },
300
324
  );
301
325
 
@@ -1,9 +1,8 @@
1
1
  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
- 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, auditImageValid } from '../dtos/audit.dtos.js';
6
- import { auditImages } from '../controllers/auditMetrics.controllers.js';
4
+ import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace } from '../controllers/audit.controllers.js';
5
+ import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
7
6
 
8
7
  export const auditRouter = express.Router();
9
8
 
@@ -18,21 +17,22 @@ auditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ),
18
17
  auditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
19
18
  auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
20
19
  auditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
21
- auditRouter.get( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
20
+ auditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
22
21
 
23
22
  // Audit Metrics
24
23
  auditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
25
24
  auditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
26
25
  auditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
27
26
  auditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
28
- auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overViewTableValid ), overViewTable );
27
+ auditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
29
28
  auditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
30
29
  auditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
31
30
  auditRouter.get( '/audit-images', isAllowedSessionHandler, validate( auditImageValid ), isAuditInputFolderExist, auditImages );
32
-
33
-
34
- // hold
31
+ // summary
35
32
  auditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
36
33
  auditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
34
+ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
37
35
 
36
+ // ticket
37
+ auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
38
38
  export default auditRouter;
@@ -1,7 +1,7 @@
1
1
  import auditStoreDataModel from 'tango-api-schema/schema/auditStoreData.model.js';
2
2
 
3
3
 
4
- export function aggregateAuditStoreDataSchema( query ) {
4
+ export function aggregateAuditStoreData( query ) {
5
5
  return auditStoreDataModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
6
  }
7
7
 
@@ -215,6 +215,7 @@ export async function getAuditImageData( data ) {
215
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
- imgPath: data,
237
- imgName: indexes[1],
238
- imgId: image[0],
237
+ img_path: data,
239
238
  img_name: indexes[1],
240
- // imgFile: auditImages[i],
239
+ img_id: image[0],
240
+ imgFile: auditImages[i],
241
241
  } );
242
242
  }
243
243
  return files;
@@ -246,7 +246,7 @@ export async function getAuditImageData( data ) {
246
246
  if ( auditImages && auditImages?.length > 0 ) {
247
247
  for ( let i = 0; i < auditImages.length; i++ ) {
248
248
  const img = auditImages[i].Key.split( '/' );
249
- const image = img[2].split( '.' );
249
+ const image = img[3].split( '.' );
250
250
  const indexes = image[0].split( '_' );
251
251
  const params = {
252
252
  file_path: auditImages[i].Key,
@@ -254,9 +254,8 @@ export async function getAuditImageData( data ) {
254
254
  };
255
255
  const data = await signedUrl( params );
256
256
  files.push( {
257
- imgPath: data,
258
- imgName: indexes[1],
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
  }
@@ -1,71 +0,0 @@
1
- import { logger } from 'tango-app-api-middleware';
2
- import { getAuditFilterData, getAuditImageData, zipDownloadImage } from '../validation/audit.validation.js';
3
- import { getReauditImg } from './audit.controllers.js';
4
- // import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
5
-
6
-
7
- export async function auditImages( req, res ) {
8
- try {
9
- const inputData = req.query;
10
- let auditImageDownload = '';
11
- switch ( inputData.imageType ) {
12
- case 'BC':
13
- const auditImageBC = await getAuditImageData( inputData );
14
- if ( auditImageBC?.errorCode ) {
15
- const error = auditImageBC?.errorMsg;
16
- const code = auditImageBC?.errorCode;
17
- return res.sendError( { error: error }, code );
18
- }
19
-
20
- if ( inputData.export==true ) {
21
- auditImageDownload= await zipDownloadImage( auditImageBC );
22
- // Set response headers for the zip file
23
- res.set( 'Content-Type', 'application/zip' );
24
- res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
25
-
26
- // Send the zip file as the API response
27
- return res.send( auditImageDownload );
28
- }
29
- res.sendSuccess( { result: auditImageBC } );
30
-
31
- break;
32
-
33
- case 'AC':
34
-
35
- const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
36
-
37
- if ( filterData?.errorCode || auditImageAC?.errorCode ) {
38
- const error = filterData?.errorMsg || auditImageAC.errorMsg;
39
- const code = filterData?.errorCode || auditImageAC.errorCode;
40
- return res.sendError( { error: error }, code );
41
- }
42
-
43
- const reauditImg = await getReauditImg( filterData, auditImageAC );
44
-
45
- logger.info( { filterData: filterData } );
46
- logger.info( { auditImageAC: auditImageAC } );
47
- logger.info( { reauditImg: reauditImg } );
48
- if ( inputData.export==true ) {
49
- auditImageDownload= await zipDownloadImage( reauditImg );
50
- // Set response headers for the zip file
51
- res.set( 'Content-Type', 'application/zip' );
52
- res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
53
-
54
- // Send the zip file as the API response
55
- return res.send( auditImageDownload );
56
- }
57
- res.sendSuccess( { result: reauditImg } );
58
- break;
59
- default:
60
- res.sendError( 'No Data Found', 204 );
61
- break;
62
- }
63
-
64
-
65
- // return res.sendSuccess( { result: inputData } );
66
- } catch ( error ) {
67
- const err = error.message || 'Internal Server Error';
68
- logger.info( { error: error, message: req.body, function: 'beforeCountImages' } );
69
- return res.sendError( err, 500 );
70
- }
71
- }