tango-app-api-audit 3.3.0-alpha.7 → 3.3.0-alpha.9

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,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.3.0-alpha.7",
3
+ "version": "3.3.0-alpha.9",
4
4
  "description": "audit & audit metrics apis",
5
- "main": "app.js",
5
+ "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node app.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node index.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -54,7 +54,7 @@ import {
54
54
  } from '../validation/audit.validation.js';
55
55
  import mongoose from 'mongoose';
56
56
  import {
57
- aggregateAuditStoreDataSchema,
57
+ aggregateAuditStoreData,
58
58
  findOneStoreData,
59
59
  } from '../service/auditStoreData.service.js';
60
60
 
@@ -1012,7 +1012,7 @@ export async function workSpace( req, res ) {
1012
1012
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
1013
1013
  const completedStoresCount = await aggregateStoreAudit( completedStores );
1014
1014
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
1015
- const auditStoreData = await aggregateAuditStoreDataSchema(
1015
+ const auditStoreData = await aggregateAuditStoreData(
1016
1016
  auditStoreDataQuery,
1017
1017
  );
1018
1018
 
@@ -1161,7 +1161,7 @@ export async function saveDraft( req, res ) {
1161
1161
  logType: 'audit',
1162
1162
  logSubType: 'auditDraft',
1163
1163
  logData: {
1164
- fileDate: insertData.fileDate,
1164
+ fileDate: inputData.fileDate,
1165
1165
  auditType: inputData.auditType,
1166
1166
  storeId: inputData.storeId,
1167
1167
  clientName: inputData.queueName,
@@ -1857,7 +1857,7 @@ export async function clientMetrics( req, res ) {
1857
1857
  );
1858
1858
  }
1859
1859
 
1860
- const count = await aggregateAuditStoreDataSchema( query );
1860
+ const count = await aggregateAuditStoreData( query );
1861
1861
  if ( count.length == 0 ) {
1862
1862
  return res.sendError( 'No Data Found', 204 );
1863
1863
  }
@@ -1889,7 +1889,7 @@ export async function clientMetrics( req, res ) {
1889
1889
  }
1890
1890
 
1891
1891
  logger.info( { query: query } );
1892
- const result = await aggregateAuditStoreDataSchema( query );
1892
+ const result = await aggregateAuditStoreData( query );
1893
1893
  if ( result.length == 0 ) {
1894
1894
  return res.sendError( 'No Data Found', 204 );
1895
1895
  }
@@ -2644,7 +2644,7 @@ export async function overAllAuditSummary( req, res ) {
2644
2644
  },
2645
2645
  },
2646
2646
  ];
2647
- const auditClientData = await aggregateAuditStoreDataSchema( auditClientDataQuery );
2647
+ const auditClientData = await aggregateAuditStoreData( auditClientDataQuery );
2648
2648
  if ( auditClientData.length >0 ) {
2649
2649
  temp.auditStores = auditClientData[0].totalFilesCount;
2650
2650
  }
@@ -2875,6 +2875,7 @@ export async function overViewCard( req, res ) {
2875
2875
  ReAuditFileCount: 0,
2876
2876
  inprogressCount: 0,
2877
2877
  completedCount: 0,
2878
+ pendingCount: 0,
2878
2879
  };
2879
2880
 
2880
2881
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2935,6 +2936,7 @@ export async function overViewCard( req, res ) {
2935
2936
  ReAuditFileCount: 1,
2936
2937
  inprogressCount: 1,
2937
2938
  completedCount: 1,
2939
+ notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
2938
2940
  },
2939
2941
  },
2940
2942
  ];
@@ -2952,14 +2954,13 @@ export async function summarySplit( req, res ) {
2952
2954
  try {
2953
2955
  const inputData = req.body;
2954
2956
  const temp = {
2955
- totalInprogress: 0,
2957
+ total: 0,
2956
2958
  auditInprogress: 0,
2957
2959
  reAuditInprogress: 0,
2958
2960
  draft: 0,
2959
2961
  assigned: 0,
2960
2962
  auditCompleted: 0,
2961
2963
  reAuditCompleted: 0,
2962
- completedCount: 0,
2963
2964
  };
2964
2965
 
2965
2966
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2970,6 +2971,9 @@ export async function summarySplit( req, res ) {
2970
2971
  if ( inputData.clientId.length > 0 ) {
2971
2972
  filters.push( { clientId: { $in: inputData.clientId } } );
2972
2973
  }
2974
+ if ( inputData?.moduleType?.length > 0 ) {
2975
+ filters.push( { moduleType: { $in: inputData.moduleType } } );
2976
+ }
2973
2977
  const query =[
2974
2978
  {
2975
2979
  $match: {
@@ -2999,11 +3003,7 @@ export async function summarySplit( req, res ) {
2999
3003
  { $ne: [ '$status', 'assigned' ] }, 1, 0,
3000
3004
  ],
3001
3005
  },
3002
- completedCount: {
3003
- $cond: [
3004
- { $eq: [ '$status', 'completed' ] }, 1, 0,
3005
- ],
3006
- },
3006
+
3007
3007
  reAuditCompleted: {
3008
3008
  $cond: [
3009
3009
  { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
@@ -3019,15 +3019,12 @@ export async function summarySplit( req, res ) {
3019
3019
  {
3020
3020
  $group: {
3021
3021
  _id: { fileDate: '$fileDate', clientId: '$clientId' },
3022
- totalInprogress: { $sum: 1 },
3023
3022
  auditInprogress: { $sum: '$auditInprogress' },
3024
3023
  reAuditInprogress: { $sum: '$reAuditInprogress' },
3025
3024
  draft: { $sum: '$draft' },
3026
3025
  assigned: { $sum: 'assigned' },
3027
- completedCount: { $sum: '$completedCount' },
3028
3026
  reAuditCompleted: { $sum: '$reAuditCompleted' },
3029
3027
  auditCompleted: { $sum: '$auditCompleted' },
3030
- completedCount: { $sum: '$completedCount' },
3031
3028
 
3032
3029
  },
3033
3030
  },
@@ -3039,14 +3036,36 @@ export async function summarySplit( req, res ) {
3039
3036
  reAuditInprogress: 1,
3040
3037
  draft: 1,
3041
3038
  assigned: 1,
3042
- completedCount: 1,
3043
3039
  reAuditCompleted: 1,
3044
3040
  auditCompleted: 1,
3041
+ totalCount: { $ifNull: [ 0, 0 ] },
3042
+
3043
+ },
3044
+ },
3045
+ ];
3046
+ const totalQuery = [
3047
+ {
3048
+ $match: {
3049
+ $and: filters,
3050
+ },
3045
3051
 
3052
+ },
3053
+ {
3054
+ $group: {
3055
+ _id: null,
3056
+ total: { $sum: 1 },
3057
+ },
3058
+ },
3059
+ {
3060
+ $project: {
3061
+ _id: 0,
3062
+ total: 1,
3046
3063
  },
3047
3064
  },
3048
3065
  ];
3049
3066
  const result = await aggregateStoreAudit( query );
3067
+ const totalCount = await aggregateAuditStoreData( totalQuery );
3068
+ result[0].totalCount = totalCount[0]?.total? totalCount[0].total : delete result[0].totalCount;
3050
3069
  logger.info( { result: result } );
3051
3070
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
3052
3071
  } catch ( error ) {
@@ -296,6 +296,7 @@ export const summarySplitSchema = joi.object(
296
296
  fromDate: joi.string().required(),
297
297
  toDate: joi.string().required(),
298
298
  clientId: joi.array().optional(),
299
+ moduleType: joi.array().optional(),
299
300
  },
300
301
  );
301
302
 
@@ -28,10 +28,9 @@ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate(
28
28
  auditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
29
29
  auditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
30
30
  auditRouter.get( '/audit-images', isAllowedSessionHandler, validate( auditImageValid ), isAuditInputFolderExist, auditImages );
31
-
32
-
33
- // hold
31
+ // summary
34
32
  auditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
35
33
  auditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
36
34
 
35
+
37
36
  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
 
package/app.js DELETED
@@ -1,38 +0,0 @@
1
- import express from 'express';
2
- import { auditRouter } from './index.js';
3
- import dotenv from 'dotenv';
4
- import { logger } from 'tango-app-api-middleware';
5
- import { connectdb } from './config/database/database.js';
6
- import responseMiddleware from './config/response/response.js';
7
- import errorMiddleware from './config/response/error.js';
8
- import pkg from 'body-parser';
9
- import { swaggerConfig } from './config/swagger/swagger.js';
10
- import swagger from 'swagger-ui-express';
11
-
12
- const { json, urlencoded } = pkg;
13
- const env=dotenv.config();
14
-
15
- const app = express();
16
- const PORT = process.env.PORT || 3000;
17
-
18
-
19
- app.use( json( { limit: '500mb' } ) );
20
- app.use(
21
- urlencoded( {
22
- extended: true,
23
- } ),
24
- );
25
- app.use( responseMiddleware );
26
- app.use( errorMiddleware );
27
- if ( env.error ) {
28
- logger.error( '.env not found' );
29
- process.exit( 1 );
30
- }
31
- app.use( '/api-docs', swagger.serve, swagger.setup( swaggerConfig ) );
32
- app.use( '/v3/audit', auditRouter );
33
-
34
- app.listen( PORT, () => {
35
- logger.info( `server is running on port= ${PORT} ` );
36
- connectdb();
37
- } );
38
-