tango-app-api-audit 3.4.11-alpha.15 → 3.4.11-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.11-alpha.15",
3
+ "version": "3.4.11-alpha.16",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -63,7 +63,7 @@ import {
63
63
  import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service.js';
64
64
  import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
65
65
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
66
- import { createAuditUserWallet } from '../service/auditUserWallet.service.js';
66
+ import { createAuditUserWallet, findOneAuditUserWallet } from '../service/auditUserWallet.service.js';
67
67
  import { aggregateAuditUsers } from '../service/auditUsers.service.js';
68
68
 
69
69
  /* < -- *** Configuration *** --> */
@@ -3888,6 +3888,25 @@ export async function auditImages( req, res ) {
3888
3888
  }
3889
3889
  }
3890
3890
 
3891
+ export async function getUserCredit( req, res ) {
3892
+ try {
3893
+ const userId=req.user.email;
3894
+ const getLastDate = await findOneAuditUserWallet( {}, {}, { fileData: -1 } );
3895
+ if ( !getLastDate ) {
3896
+ return res.sendError( 'No records found', 204 );
3897
+ }
3898
+ const getWallet = await findOneAuditUserWallet( { fileDate: getLastDate.fileDate, userEmail: userId }, { totalCredit: 1, fileDate: 1 } );
3899
+ if ( !getWallet ) {
3900
+ return res.sendSuccess( { result: 0 } );
3901
+ }
3902
+ return res.sendSuccess( { result: getWallet, isAuditUser: true } );
3903
+ } catch ( error ) {
3904
+ const err = error.message || 'Internal Server Error';
3905
+ logger.info( { error: error, function: 'getUserCredit' } );
3906
+ return res.sendError( err, 500 );
3907
+ }
3908
+ }
3909
+
3891
3910
  export async function getUserAuditCount( req, res ) {
3892
3911
  try {
3893
3912
  const userWallet = JSON.parse( process.env.USER_WALLET );
@@ -544,6 +544,20 @@ export const auditDocs = {
544
544
  },
545
545
  },
546
546
  },
547
+ '/v3/audit/get-user-credit': {
548
+ get: {
549
+ tags: [ 'Audit User Wallet' ],
550
+ description: 'Get single past date credit',
551
+ operationId: 'get-user-credit',
552
+ responses: {
553
+ 200: { description: 'Successful' },
554
+ 401: { description: 'Unauthorized User' },
555
+ 422: { description: 'Field Error' },
556
+ 500: { description: 'Server Error' },
557
+ 204: { description: 'Not Found' },
558
+ },
559
+ },
560
+ },
547
561
  '/v3/audit/get-user-audit-count': {
548
562
  get: {
549
563
  tags: [ 'Audit User Wallet' ],
@@ -1,7 +1,7 @@
1
1
  import express from 'express';
2
- import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
2
+ import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs } from '../controllers/audit.controllers.js';
4
+ import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs, getUserCredit } from '../controllers/audit.controllers.js';
5
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';
6
6
 
7
7
  export const auditRouter = express.Router();
@@ -37,6 +37,7 @@ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate(
37
37
  auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
38
38
 
39
39
  // audit user wallet
40
+ auditRouter.get( '/get-user-credit', isAllowedSessionHandler, isAuditUser, getUserCredit );
40
41
  auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
41
42
  auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
42
43
 
@@ -5,6 +5,10 @@ export function createAuditUserWallet( record ) {
5
5
  return auditUserWalletModel.create( record );
6
6
  };
7
7
 
8
+ export function findOneAuditUserWallet( record, fields, sort = { createdAt: -1 } ) {
9
+ return auditUserWalletModel.findOne( record, fields ).sort( sort );
10
+ };
11
+
8
12
  export function updateManyAuditUserWallet( query, record ) {
9
13
  return auditUserWalletModel.updateMany( query, record, { upsert: true } );
10
14
  };
@@ -3,3 +3,7 @@ import auditUsersModel from 'tango-api-schema/schema/auditUsers.model.js';
3
3
  export function aggregateAuditUsers( query ) {
4
4
  return auditUsersModel.aggregate( query );
5
5
  };
6
+
7
+ export function findOneAuditUsers( query, fields ) {
8
+ return auditUsersModel.findOne( query, fields );
9
+ };
@@ -2,6 +2,7 @@ import { checkFileExist, chunkArray, getJsonFileData, getObject, getQueueUrl, li
2
2
  import { findOneUserAudit } from '../service/userAudit.service.js';
3
3
  import { findOneStoreAudit } from '../service/storeAudit.service.js';
4
4
  import AdmZip from 'adm-zip';
5
+ import { findOneAuditUsers } from '../service/auditUsers.service.js';
5
6
 
6
7
  export async function isExistsQueue( req, res, next ) {
7
8
  try {
@@ -333,4 +334,18 @@ export async function getAuditFilterData( data ) {
333
334
  }
334
335
  }
335
336
 
337
+ export async function isAuditUser( req, res, next ) {
338
+ try {
339
+ const userEmail = req.user?.email;
340
+ const getAuditUser = await findOneAuditUsers( { email: userEmail, isActive: true } );
341
+ if ( !getAuditUser ) {
342
+ return res.sendSuccess( { result: 0, isAuditUser: false } );
343
+ }
344
+ return next();
345
+ } catch ( error ) {
346
+ const err = error.message || 'Internal Server Error';
347
+ logger.error( { error: error, function: 'isAuditUser' } );
348
+ return res.sendError( err, 500 );
349
+ }
350
+ }
336
351