tango-app-api-audit 3.4.3-alpha.14 → 3.4.3-alpha.16

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": "3.4.3-alpha.14",
3
+ "version": "3.4.3-alpha.16",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "mongodb": "^6.7.0",
25
25
  "nodemon": "^3.1.3",
26
26
  "swagger-ui-express": "^5.0.1",
27
- "tango-api-schema": "^2.1.25",
27
+ "tango-api-schema": "^2.1.28",
28
28
  "tango-app-api-middleware": "^3.1.33",
29
29
  "winston": "^3.13.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
@@ -1218,6 +1218,7 @@ export async function getDraftedData( req, res ) {
1218
1218
  userId: userId,
1219
1219
  moduleType: inputData.moduleType,
1220
1220
  zoneName: inputData.zoneName,
1221
+ auditId: inputData.auditId,
1221
1222
  };
1222
1223
  const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
1223
1224
 
@@ -4429,24 +4430,25 @@ export async function auditViewLogs( req, res ) {
4429
4430
  try {
4430
4431
  const inputData = req.query;
4431
4432
  const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
4432
- let downTimeQuery = {
4433
+ const logData =[];
4434
+ let logsQuery = {
4433
4435
  'size': 100,
4434
4436
  'query': {
4435
4437
  'bool': {
4436
4438
  'must': [
4437
4439
  {
4438
4440
  'term': {
4439
- 'doc.logData.fileDate.keyword': dayjs( inputData.fileDate ).format( 'DD-MM-YYYY' ),
4441
+ 'logData.fileDate.keyword': inputData.fileDate,
4440
4442
  },
4441
4443
  },
4442
4444
  {
4443
4445
  'term': {
4444
- 'doc.logData.storeId.keyword': inputData.storeId,
4446
+ 'logData.storeId.keyword': inputData.storeId,
4445
4447
  },
4446
4448
  },
4447
4449
  {
4448
4450
  'term': {
4449
- 'doc.logData.moduleType.keyword': inputData.moduleType,
4451
+ 'logData.moduleType.keyword': inputData.moduleType,
4450
4452
  },
4451
4453
  },
4452
4454
  ],
@@ -4454,10 +4456,17 @@ export async function auditViewLogs( req, res ) {
4454
4456
  },
4455
4457
  },
4456
4458
  };
4457
- const downtime = await getOpenSearchData( parsedOpenSearch.auditLog, downTimeQuery );
4458
- return res.sendSuccess( downtime );
4459
- } catch ( err ) {
4460
-
4459
+ const logs = await getOpenSearchData( parsedOpenSearch.auditLog, logsQuery );
4460
+ if ( logs.body.hits.hits.length > 0 ) {
4461
+ logData.push( logs.body.hits.hits[0]._source );
4462
+ return res.sendSuccess( logData );
4463
+ } else {
4464
+ return res.sendError( 'No Record Inserted', 500 );
4465
+ }
4466
+ } catch ( error ) {
4467
+ const err = error.message || 'Internal Server Error';
4468
+ logger.info( { error: error, message: req.body, function: 'auditViewLogs' } );
4469
+ return res.sendError( err, 500 );
4461
4470
  }
4462
4471
  }
4463
4472
 
@@ -2,7 +2,7 @@ import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime
2
2
  import { aggregateBinaryAudit, createBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
3
  import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
5
- import { aggregateUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
5
+ import { aggregateUserEmpDetection, countDocumentsUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
6
6
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
7
7
  import { aggregateClient, findOneClient } from '../service/client.service.js';
8
8
  import dayjs from 'dayjs';
@@ -4212,6 +4212,7 @@ export async function getDraftedData( req, res ) {
4212
4212
  storeId: inputData.storeId,
4213
4213
  userId: userId,
4214
4214
  moduleType: inputData.moduleType,
4215
+ auditId: inputData.auditId,
4215
4216
  };
4216
4217
  const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
4217
4218
 
@@ -4233,13 +4234,29 @@ export async function getDraftedData( req, res ) {
4233
4234
  export async function save( req, res ) {
4234
4235
  try {
4235
4236
  const inputData = req.body;
4237
+ const isoDate = req.userAudit?.startTime;
4238
+ const currentTime = dayjs();
4239
+ const isoDateTime = dayjs( isoDate );
4240
+ const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
4236
4241
  const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
4237
4242
  inputData.clientId = getUserAuditData.clientId;
4238
4243
  const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
4239
4244
  const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
4240
4245
  if ( data ) {
4241
- await updateOneUserEmpDetection( { _id: inputData.auditId }, { auditStatus: 'completed', afterCount: inputData.employeeCount } );
4242
- await updateOneStoreEmpDetection( query, { status: 'completed', afterCount: inputData.employeeCount } );
4246
+ const userUpdated ={
4247
+ auditStatus: 'completed',
4248
+ afterCount: inputData.employeeCount,
4249
+ endTime: Date.now(),
4250
+ isDraft: false,
4251
+ timeSpent: timeDifferenceInMinutes,
4252
+ };
4253
+ const storeUpdated ={
4254
+ status: 'completed',
4255
+ afterCount: inputData.employeeCount,
4256
+ timeSpent: timeDifferenceInMinutes,
4257
+ };
4258
+ await updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated );
4259
+ await updateOneStoreEmpDetection( query, storeUpdated );
4243
4260
  return res.sendSuccess( { result: 'Updated Successfully' } );
4244
4261
  } else {
4245
4262
  return res.sendError( 'something went wrong', 403 );
@@ -4266,6 +4283,9 @@ export async function reTrigger( req, res ) {
4266
4283
  if ( !getQueueName || queueName == '' ) {
4267
4284
  return res.sendError( 'queueName does not create', 400 );
4268
4285
  }
4286
+ const getRecord = await countDocumentsUserEmpDetection( { storeId: message.storeId,
4287
+ fileDate: message.fileDate,
4288
+ moduleType: message.moduleType, auditStatus: 'completed' } );
4269
4289
  const msg = {
4270
4290
  storeId: message.storeId,
4271
4291
  fileDate: message.fileDate,
@@ -4275,6 +4295,7 @@ export async function reTrigger( req, res ) {
4275
4295
  question: message.question,
4276
4296
  folderPath: message.folderPath,
4277
4297
  fileCount: message.fileCount,
4298
+ auditType: getRecord > 0? 'ReAudit':'Audit',
4278
4299
  };
4279
4300
  const sqsProduceQueue = {
4280
4301
  QueueUrl: `${sqs.url}${queueName}`,
@@ -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',
@@ -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',
@@ -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 = {
@@ -68,6 +68,7 @@ export const getDraftedDataSchema = joi.object(
68
68
  fileDate: joi.string().required(),
69
69
  userId: joi.string().optional(),
70
70
  moduleType: joi.string().required(),
71
+ auditId: joi.string().required(),
71
72
  },
72
73
  );
73
74
 
@@ -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
  }