tango-app-api-audit 1.0.60 → 1.0.62

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.60",
3
+ "version": "1.0.62",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -31,9 +31,9 @@ import {
31
31
  } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
32
32
  import {
33
33
  aggregateStoreAudit,
34
- createStoreAudit,
35
- findOneStoreAudit,
34
+ // findOneStoreAudit,
36
35
  updateOneStoreAudit,
36
+ updateStoreAudit,
37
37
  } from '../service/storeAudit.service.js';
38
38
  import _ from 'lodash';
39
39
  import {
@@ -410,6 +410,12 @@ export async function getAuditFile( req, res ) {
410
410
  zoneName: msg.zone_id,
411
411
  moduleType: inputData.moduleType,
412
412
  };
413
+ const query ={
414
+ storeId: msg.store_id,
415
+ zoneName: msg.zone_id,
416
+ fileDate: msg.curr_date,
417
+ moduleType: inputData.moduleType,
418
+ };
413
419
  const storeRecord = {
414
420
  userId: req.user._id,
415
421
  storeId: msg.store_id,
@@ -425,7 +431,7 @@ export async function getAuditFile( req, res ) {
425
431
  moduleType: inputData.moduleType,
426
432
  };
427
433
  reauditInsert = await createUserAudit( record );
428
- await createStoreAudit( storeRecord );
434
+ await updateStoreAudit( query, storeRecord );
429
435
  } else {
430
436
  reauditInsert = userDetails[0];
431
437
  }
@@ -539,6 +545,12 @@ export async function getAuditFile( req, res ) {
539
545
  zoneName: msg.zone_id,
540
546
  moduleType: inputData.moduleType,
541
547
  };
548
+ const query ={
549
+ storeId: msg.store_id,
550
+ zoneName: msg.zone_id,
551
+ fileDate: msg.curr_date,
552
+ moduleType: inputData.moduleType,
553
+ };
542
554
  const storeRecord = {
543
555
  userId: req.user._id,
544
556
  storeId: msg.store_id,
@@ -555,7 +567,7 @@ export async function getAuditFile( req, res ) {
555
567
  };
556
568
 
557
569
  insertData = await createUserAudit( record );
558
- await createStoreAudit( storeRecord );
570
+ await updateStoreAudit( query, storeRecord );
559
571
  } else {
560
572
  insertData = userDetails[0];
561
573
  }
@@ -1208,21 +1220,21 @@ export async function save( req, res ) {
1208
1220
  const bucket = JSON.parse( process.env.BUCKET );
1209
1221
  const sqs = JSON.parse( process.env.SQS );
1210
1222
  const inputData = req.body;
1211
- let storeAuditData = await findOneStoreAudit( {
1212
- storeId: inputData.storeId,
1213
- fileDate: inputData.fileDate,
1214
- moduleType: inputData.moduleType,
1215
- zoneName: inputData.zoneName,
1216
- auditType: inputData.auditType,
1217
- } );
1218
- logger.info( { storeAuditData: storeAuditData } );
1219
- if ( storeAuditData==null ) {
1220
- logger.error( {
1221
- error: `No data found: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
1222
- type: 'DATABASE_RECORD_NOTFOUND',
1223
- } );
1224
- return res.sendError( storeAuditData, 204 );
1225
- }
1223
+ // let storeAuditData = await findOneStoreAudit( {
1224
+ // storeId: inputData.storeId,
1225
+ // fileDate: inputData.fileDate,
1226
+ // moduleType: inputData.moduleType,
1227
+ // zoneName: inputData.zoneName,
1228
+ // auditType: inputData.auditType,
1229
+ // } );
1230
+ // logger.info( { storeAuditData: storeAuditData } );
1231
+ // if ( storeAuditData==null ) {
1232
+ // logger.error( {
1233
+ // error: `No data found: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
1234
+ // type: 'DATABASE_RECORD_NOTFOUND',
1235
+ // } );
1236
+ // return res.sendError( storeAuditData, 204 );
1237
+ // }
1226
1238
  const params = {
1227
1239
  Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
1228
1240
  };
@@ -1406,7 +1418,7 @@ export async function save( req, res ) {
1406
1418
  } catch ( error ) {
1407
1419
  const err = error.message || 'Internal Server Error';
1408
1420
  logger.error( { error: error, message: req.body, function: 'save' } );
1409
- return res.sendError( err );
1421
+ return res.sendError( err, 500 );
1410
1422
  }
1411
1423
  }
1412
1424
 
@@ -4,6 +4,10 @@ export function updateOneStoreAudit( query, record ) {
4
4
  return storeAuditModel.updateOne( query, { $set: record } );
5
5
  }
6
6
 
7
+ export function updateStoreAudit( query, record ) {
8
+ return storeAuditModel.update( query, { $set: record }, { upsert: true } );
9
+ }
10
+
7
11
  export function createStoreAudit( record ) {
8
12
  return storeAuditModel.create( record );
9
13
  }