tango-app-api-audit 3.4.3-alpha.2 → 3.4.3-alpha.20

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.
@@ -184,6 +184,12 @@ export const auditDocs = {
184
184
  scema: j2s( getDraftedDataSchema ).swagger,
185
185
  require: true,
186
186
  },
187
+ {
188
+ in: 'query',
189
+ name: 'auditId',
190
+ scema: j2s( getDraftedDataSchema ).swagger,
191
+ require: true,
192
+ },
187
193
  {
188
194
  in: 'query',
189
195
  name: 'userId',
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema } from '../dtos/traxAudit.dtos.js';
2
+ import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
3
3
 
4
4
  export const traxAuditDocs = {
5
5
 
@@ -387,6 +387,12 @@ export const traxAuditDocs = {
387
387
  scema: j2s( getDraftedDataSchema ).swagger,
388
388
  require: true,
389
389
  },
390
+ {
391
+ in: 'query',
392
+ name: 'auditId',
393
+ scema: j2s( getDraftedDataSchema ).swagger,
394
+ require: true,
395
+ },
390
396
  {
391
397
  in: 'query',
392
398
  name: 'userId',
@@ -403,4 +409,26 @@ export const traxAuditDocs = {
403
409
  },
404
410
  },
405
411
  },
412
+ '/v3/trax-audit/metrics/re-trigger': {
413
+ post: {
414
+ tags: [ 'Trax Audit' ],
415
+ description: `Manual re trigger a file`,
416
+ operationId: 'metrics/re-trigger',
417
+ parameters: {},
418
+ requestBody: {
419
+ content: {
420
+ 'application/json': {
421
+ schema: j2s( reTriggerValidSchema ).swagger,
422
+ },
423
+ },
424
+ },
425
+ responses: {
426
+ 200: { description: 'Successful' },
427
+ 401: { description: 'Unauthorized User' },
428
+ 422: { description: 'Field Error' },
429
+ 500: { description: 'Server Error' },
430
+ 204: { description: 'Not Found' },
431
+ },
432
+ },
433
+ },
406
434
  };
@@ -76,6 +76,7 @@ export const getDraftedDataSchema = joi.object( {
76
76
  userId: joi.string().optional(),
77
77
  moduleType: joi.string().required(),
78
78
  zoneName: joi.string().required(),
79
+ auditId: joi.string().required(),
79
80
  } );
80
81
 
81
82
  export const getDraftedDataValid = {
@@ -266,7 +267,7 @@ export const reTriggerValid = {
266
267
  export const overViewCardSchema = joi.object( {
267
268
  fromDate: joi.string().required(),
268
269
  toDate: joi.string().required(),
269
- clientId: joi.array().items( joi.string().required() ).required(),
270
+ clientId: joi.array().items( joi.string().required().allow( '' ) ).required(),
270
271
  } );
271
272
 
272
273
  export const overViewCardValid = {
@@ -45,7 +45,6 @@ export const saveDraftSchema = joi.object(
45
45
  storeId: joi.string().required(),
46
46
  auditId: joi.string().required(),
47
47
  moduleType: joi.string().required(),
48
- // zoneName: joi.string().required(),
49
48
  auditType: joi.string().required(),
50
49
  fileDate: joi.string().required(),
51
50
  queueName: joi.string().required(),
@@ -69,6 +68,7 @@ export const getDraftedDataSchema = joi.object(
69
68
  fileDate: joi.string().required(),
70
69
  userId: joi.string().optional(),
71
70
  moduleType: joi.string().required(),
71
+ auditId: joi.string().required(),
72
72
  },
73
73
  );
74
74
 
@@ -273,8 +273,6 @@ export const saveSchema = joi.object( {
273
273
  auditType: joi.string().required(),
274
274
  moduleType: joi.string().required(),
275
275
  beforeCount: joi.number().required(),
276
- junkCount: joi.number().required(),
277
- junk: joi.array().required(),
278
276
  employeeCount: joi.number().required(),
279
277
  employee: joi.array().required(),
280
278
  } );
@@ -282,3 +280,15 @@ export const saveSchema = joi.object( {
282
280
  export const saveValid = {
283
281
  body: saveSchema,
284
282
  };
283
+
284
+
285
+ export const reTriggerValidSchema = joi.object( {
286
+ fileDate: joi.string().required(),
287
+ storeId: joi.string().required(),
288
+ moduleType: joi.string().required(),
289
+
290
+ } );
291
+
292
+ export const reTriggerValid = {
293
+ body: reTriggerValidSchema,
294
+ };
@@ -41,5 +41,5 @@ auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditC
41
41
  auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
42
42
 
43
43
  // audit log
44
- auditRouter.get( '/audit-viewLogs', auditViewLogs );
44
+ auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, auditViewLogs );
45
45
  export default auditRouter;
@@ -1,16 +1,16 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
- import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid } from '../dtos/traxAudit.dtos.js';
3
+ import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
4
4
  import { isExistsQueue } from '../validation/audit.validation.js';
5
- import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save } from '../controllers/traxAudit.controllers.js';
6
- import { isTraxAuditDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
5
+ import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
6
+ import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit, validateUserEmpDetection } from '../validation/traxAuditValidation.js';
7
7
 
8
8
  export const traxAuditRouter = Router();
9
9
 
10
10
  // Audit Mapping
11
11
 
12
12
  traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
13
- traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, save );
13
+ traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, validateUserEmpDetection, save );
14
14
  traxAuditRouter.post( '/save-draft', validate( saveDraftValid ), isAllowedSessionHandler, saveDraft );
15
15
  traxAuditRouter.get( '/get-drafted-data', validate( getDraftedDataValid ), isAllowedSessionHandler, getDraftedData );
16
16
 
@@ -28,6 +28,7 @@ traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validat
28
28
  traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
29
29
  traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
30
30
  traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
31
+ traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValidSchema ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
31
32
 
32
33
  // summary
33
34
 
@@ -1,5 +1,5 @@
1
1
  import auditUserWalletModel from 'tango-api-schema/schema/auditUserWallet.model.js';
2
-
2
+ import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
3
3
 
4
4
  export function createAuditUserWallet( record ) {
5
5
  return auditUserWalletModel.create( record );
@@ -8,3 +8,6 @@ export function createAuditUserWallet( record ) {
8
8
  export function updateManyAuditUserWallet( query, record ) {
9
9
  return auditUserWalletModel.updateMany( query, record, { upsert: true } );
10
10
  };
11
+ export function createempDetectionOutput( query, field, option ) {
12
+ return empDetectionOutputModel.updateOne( query, field, option );
13
+ };
@@ -0,0 +1,5 @@
1
+ import auditUsersModel from 'tango-api-schema/schema/auditUsers.model.js';
2
+
3
+ export function aggregateAuditUsers( query ) {
4
+ return auditUsersModel.aggregate( query );
5
+ };
@@ -1,5 +1,5 @@
1
1
 
2
2
  import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
3
- export function createAuditLog( record ) {
4
- return empDetectionOutputModel.create( record );
3
+ export function updateOneEmpDetectionOutput( query, record, upsert ) {
4
+ return empDetectionOutputModel.updateOne( query, record, upsert );
5
5
  }
@@ -5,9 +5,14 @@ export function aggregateStoreEmpDetection( query ) {
5
5
  return storeEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
6
  }
7
7
 
8
+ export function findOneStoreEmpDetection( query ) {
9
+ return storeEmpDetectionModel.findOne( query );
10
+ }
11
+
8
12
  export function updateOneStoreEmpDetection( query, record ) {
9
13
  return storeEmpDetectionModel.updateOne( query, { $set: record } );
10
14
  }
15
+
11
16
  export function updateManyStoreEmpDetection( query, record ) {
12
17
  return storeEmpDetectionModel.updateMany( query, { $set: record }, { upsert: true } );
13
18
  }
@@ -1,9 +1,7 @@
1
1
  import userEmpDetectionModel from 'tango-api-schema/schema/userEmpDetection.model.js';
2
- import { logger } from 'tango-app-api-middleware';
3
2
 
4
3
 
5
4
  export function aggregateUserEmpDetection( query ) {
6
- logger.info( { seelevt: 'yryruteretwyyyyyyyyyyyyyyyyyyyyyyyyyyyyewe' } );
7
5
  return userEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
8
6
  }
9
7
 
@@ -15,6 +13,10 @@ export function findOneUserEmpDetection( query, fields ) {
15
13
  return userEmpDetectionModel.findOne( query, fields );
16
14
  }
17
15
 
16
+ export function countDocumentsUserEmpDetection( query, fields ) {
17
+ return userEmpDetectionModel.countDocuments( query, fields );
18
+ }
19
+
18
20
  export function updateOneUserEmpDetection( query, record ) {
19
21
  return userEmpDetectionModel.updateOne( query, { $set: record } );
20
22
  }
@@ -1,7 +1,8 @@
1
- import { logger } from 'tango-app-api-middleware';
1
+ import { checkFileExist, logger } from 'tango-app-api-middleware';
2
2
  import { findOneBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
3
  import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
4
4
  import { findOneTraxAuditData } from '../service/traxAuditData.service.js';
5
+ import { findOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
5
6
 
6
7
  export async function validateUserEmpDetection( req, res, next ) {
7
8
  try {
@@ -116,3 +117,48 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
116
117
  return res.sendError( err, 500 );
117
118
  }
118
119
  }
120
+
121
+ export async function isuserEmpDocumentExist( req, res, next ) {
122
+ try {
123
+ const inputData = req.body;
124
+ const query={
125
+ storeId: inputData.storeId,
126
+ fileDate: inputData.fileDate,
127
+ moduleType: inputData.moduleType,
128
+ };
129
+ const auditInfo = await findOneStoreEmpDetection( query );
130
+ if ( auditInfo ) {
131
+ const sqs = await findOneTraxAuditData( query, { sqs: 1 } );
132
+ req.sqs = sqs.sqs.Body;
133
+ req.audit = auditInfo;
134
+ return next();
135
+ } else {
136
+ return res.sendError( 'No audited Record', 400 );
137
+ }
138
+ } catch ( error ) {
139
+ const err = error.message || 'Internal Server Error';
140
+ logger.error( { error: error, message: req.body, function: 'isAuditFileExist' } );
141
+ return res.sendError( err, 500 );
142
+ }
143
+ }
144
+
145
+
146
+ export async function isMappingAuditInputFolderExist( req, res, next ) {
147
+ try {
148
+ // const inputData = req.method === 'POST' ? req.body : req.query;
149
+ const params={
150
+ Bucket: req.sqs.inputBucketName,
151
+ Key: req.sqs.folderPath.replace( /\/$/, '' ),
152
+ };
153
+ const isExist = await checkFileExist( params );
154
+ if ( isExist ) {
155
+ next();
156
+ } else {
157
+ return res.sendError( `Audit Input folder not available : ${req.sqs.folderPath}`, 400 );
158
+ }
159
+ } catch ( error ) {
160
+ const err = error.message || 'Internal Server Error';
161
+ logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
162
+ return res.sendError( err, 500 );
163
+ }
164
+ }