tango-app-api-audit 1.0.7 → 1.0.8

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.7",
3
+ "version": "1.0.8",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -19,6 +19,7 @@
19
19
  "express": "^4.19.2",
20
20
  "handlebars": "^4.7.8",
21
21
  "joi-to-swagger": "^6.2.0",
22
+ "lodash": "^4.17.21",
22
23
  "mongodb": "^6.7.0",
23
24
  "nodemon": "^3.1.3",
24
25
  "swagger-ui-express": "^5.0.1",
@@ -1,12 +1,14 @@
1
- import { chunkArray, getJsonFileData, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
1
+ import { chunkArray, download, getJsonFileData, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
2
2
  import { aggregateUserAudit, createUserAudit, findOneUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
3
3
  import { aggregateAssignAudit, updateOneAssignAudit } from '../service/assignAudit.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
5
5
  import dayjs from 'dayjs';
6
6
  import { aggregateClient } from '../service/client.service.js';
7
7
  import { logger } from 'tango-app-api-middleware';
8
- import { sqsReceive } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
9
- import { createStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
8
+ import { listQueue, sqsReceive } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
9
+ import { aggregateStoreAudit, createStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
10
+ import { aggregateAuditClientData } from '../service/auditClientData.service.js';
11
+ import _ from 'lodash';
10
12
 
11
13
  export async function getAuditFile( req, res ) {
12
14
  try {
@@ -448,17 +450,19 @@ export const mapFunction = async ( chunk, filter ) => {
448
450
  return temp;
449
451
  };
450
452
 
451
- export async function getQueueDetailList( req, res ) {
453
+ export async function workSpace( req, res ) {
452
454
  try {
453
455
  const inputData = req.query;
454
- const data = await getUTC( new Date(), new Date() );
456
+ const limit = inputData.limit || 10;
457
+ const offset =inputData.offset? ( inputData.offset - 1 ) * inputData.limit : 0;
458
+ const dateRange = await getUTC( new Date(), new Date() );
455
459
 
456
460
  const temp = [];
457
461
  const clientQuery = [
458
462
  {
459
463
  $match: {
460
464
  $and: [
461
- { active: { $in: [ 'active', 'hold' ] } },
465
+ { status: { $in: [ 'active', 'hold' ] } },
462
466
  { 'auditConfigs.audit': { $eq: true } },
463
467
  ],
464
468
  },
@@ -482,16 +486,16 @@ export async function getQueueDetailList( req, res ) {
482
486
  } );
483
487
  }
484
488
  const count = await aggregateClient( clientQuery );
485
- if ( inputData.limit && inputData.offset && !inputData.export ) {
486
- const skip = ( inputData.offset - 1 ) * inputData.limit;
487
- clientQuery.push( { $skip: skip }, { $limit: inputData.limit } );
489
+ logger.info( { count: count } );
490
+ if ( count?.length == 0 ) {
491
+ return res.sendError( 'No Data Found', 204 );
488
492
  }
489
493
 
490
- const clientDetails = await aggregateClient( clientQuery );
491
- if ( clientDetails && clientDetails.length === 0 ) {
492
- return res.sendError( 'No Data Found', 204 );
494
+ if ( inputData.limit && !inputData.isExport ) {
495
+ clientQuery.push( { $skip: offset }, { $limit: limit } );
493
496
  }
494
497
 
498
+ const clientDetails = await aggregateClient( clientQuery );
495
499
  const clientList = clientDetails.map( ( i ) => i.clientId );
496
500
  const query = [
497
501
  {
@@ -519,7 +523,7 @@ export async function getQueueDetailList( req, res ) {
519
523
  },
520
524
  ];
521
525
 
522
- const fileDate = dayjs( data.start ).subtract( 1, 'days' );
526
+ const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
523
527
 
524
528
  const completedFiles = [
525
529
  {
@@ -534,7 +538,7 @@ export async function getQueueDetailList( req, res ) {
534
538
  $project: {
535
539
  clientId: 1,
536
540
  completed: {
537
- $cond: [ { $eq: [ '$storeStatus', 'completed' ] }, 1, 0 ],
541
+ $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ],
538
542
  },
539
543
  },
540
544
  },
@@ -560,8 +564,8 @@ export async function getQueueDetailList( req, res ) {
560
564
  $match: {
561
565
  $and: [
562
566
  { clientId: { $in: clientList } },
563
- { createdAt: { $gte: data.start } },
564
- { createdAt: { $lte: data.end } },
567
+ { createdAt: { $gte: dateRange.start } },
568
+ { createdAt: { $lte: dateRange.end } },
565
569
  ],
566
570
  },
567
571
  },
@@ -569,7 +573,7 @@ export async function getQueueDetailList( req, res ) {
569
573
  $project: {
570
574
  clientId: 1,
571
575
  pending: {
572
- $cond: [ { $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] }, { $in: [ '$storeStatus', [ 'skipped' ] ] } ] }, 1, 0 ],
576
+ $cond: [ { $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] } ] }, 1, 0 ],
573
577
  },
574
578
  },
575
579
  },
@@ -599,8 +603,8 @@ export async function getQueueDetailList( req, res ) {
599
603
  $and: [
600
604
  { clientId: { $in: clientList } },
601
605
  { userId: { $eq: inputData.userId } },
602
- { createdAt: { $gte: data.start } },
603
- { createdAt: { $lte: data.end } },
606
+ { createdAt: { $gte: dateRange.start } },
607
+ { createdAt: { $lte: dateRange.end } },
604
608
  ],
605
609
  },
606
610
  },
@@ -686,14 +690,14 @@ export async function getQueueDetailList( req, res ) {
686
690
  },
687
691
  ];
688
692
 
689
- const auditDetails = await AuditFilesModel.aggregate( query );
690
- const auditCount = await audit.aggregate( auditFiles );
691
- const draftedCount = await audit.aggregate( draftedFiles );
692
- const CompletedCount = await audit.aggregate( completedFiles );
693
+ const auditDetails = await aggregateAuditClientData( query );
694
+ const auditCount = await aggregateUserAudit( auditFiles );
695
+ const draftedCount = await aggregateUserAudit( draftedFiles );
696
+ const CompletedCount = await aggregateStoreAudit( completedFiles );
693
697
 
694
- const clientAssignresult = await auditUserAssignModel.aggregate( clientAssign );
698
+ const clientAssignresult = await aggregateAssignAudit( clientAssign );
695
699
 
696
- const userAsignCount = await auditUserAssignModel.aggregate( userAsign );
700
+ const userAsignCount = await aggregateAssignAudit( userAsign );
697
701
  const mergeAll = _.merge( _.keyBy( clientDetails, 'clientId' ), _.keyBy( auditCount, 'clientId' ), _.keyBy( draftedCount, 'clientId' ), _.keyBy( clientAssignresult, 'clientId' ) );
698
702
  const finalResult = _.values( mergeAll );
699
703
  const merge = _.values( _.merge( _.keyBy( finalResult, 'clientId' ), _.keyBy( auditDetails, 'clientId' ), _.keyBy( userAsignCount, 'clientId' ), _.keyBy( CompletedCount, 'clientId' ) ) );
@@ -705,13 +709,13 @@ export async function getQueueDetailList( req, res ) {
705
709
  const pending = await listQueue( merge[i].queueName );
706
710
  if ( !pending.statusCode ) {
707
711
  temp.push( {
708
- client_id: merge[i].clientId,
709
- client_name: merge[i].clientName,
712
+ clientId: merge[i].clientId,
713
+ clientName: merge[i].clientName,
710
714
  completedCount: merge[i].completedCount ? Number( merge[i].completedCount ) : 0,
711
715
  pendingByQueue: Number( pending ),
712
716
  pendingByUser: ( merge[i].pendingCount >= 0 ) ? Number( merge[i].pendingCount )+( merge[i].ClientAsignedCount ? Number( merge[i].ClientAsignedCount ) : 0 ) : 0,
713
717
  totalCount: merge[i].totalFilesCount,
714
- queue_name: merge[i].queueName,
718
+ queueName: merge[i].queueName,
715
719
  isDraft: merge[i].isDrafted ? merge[i].isDrafted : false,
716
720
  isEnable: Number( pending ) > 0 || merge[i].isDrafted || ( merge[i].asignedCount && merge[i].asignedCount > 0 ) || ( merge[i].inprogressCount && merge[i].inprogressCount > 0 ) ? true : false,
717
721
  completedRatio: merge[i].totalFilesCount ? merge[i].completedCount ? Math.round( ( Number( merge[i].completedCount ) / Number( merge[i].totalFilesCount ) ) * 100 ) : 0 : 0,
@@ -721,7 +725,7 @@ export async function getQueueDetailList( req, res ) {
721
725
  }
722
726
  }
723
727
 
724
- if ( inputData.export == 'true' ) {
728
+ if ( inputData.isExport ) {
725
729
  const exportdata = [];
726
730
  temp.forEach( ( element ) => {
727
731
  exportdata.push( {
@@ -741,7 +745,9 @@ export async function getQueueDetailList( req, res ) {
741
745
  return res.sendSuccess( { result: temp, count: count.length, totalStores: totalStores } );
742
746
  }
743
747
  } catch ( error ) {
744
- return res.sendError( error );
748
+ const err = error.message || 'Internal Server Error';
749
+ logger.info( { error: error, message: req.query, function: 'workSpace' } );
750
+ return res.sendError( err, 500 );
745
751
  }
746
752
  }
747
753
 
@@ -1,4 +1,4 @@
1
- import { getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema } from '../dtos/audit.dtos.js';
1
+ import { getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema, workSpaceSchema } from '../dtos/audit.dtos.js';
2
2
  import j2s from 'joi-to-swagger';
3
3
 
4
4
  export const auditDocs = {
@@ -108,4 +108,45 @@ export const auditDocs = {
108
108
  },
109
109
  },
110
110
  },
111
+ '/v3/audit/work-space': {
112
+ get: {
113
+ tags: [ 'Audit' ],
114
+ description: 'queue wise info of audit files ',
115
+ operationId: 'work-space',
116
+ parameters: [
117
+ {
118
+ in: 'query',
119
+ name: 'searchValue',
120
+ scema: j2s( workSpaceSchema ).swagger,
121
+ require: false,
122
+ },
123
+ {
124
+ in: 'query',
125
+ name: 'offset',
126
+ scema: j2s( workSpaceSchema ).swagger,
127
+ require: false,
128
+ },
129
+ {
130
+ in: 'query',
131
+ name: 'limit',
132
+ scema: j2s( workSpaceSchema ).swagger,
133
+ require: false,
134
+ },
135
+ {
136
+ in: 'query',
137
+ name: 'isExport',
138
+ scema: j2s( workSpaceSchema ).swagger,
139
+ require: false,
140
+ },
141
+ ],
142
+ responses: {
143
+ 200: { description: 'Successful' },
144
+ 401: { description: 'Unauthorized User' },
145
+ 422: { description: 'Field Error' },
146
+ 500: { description: 'Server Error' },
147
+ 204: { description: 'Not Found' },
148
+ },
149
+ },
150
+ },
151
+
111
152
  };
@@ -4,7 +4,7 @@ import joi from 'joi';
4
4
  export const getFileSchema = joi.object(
5
5
  {
6
6
  queueName: joi.string().required(),
7
- nextId: joi.string().optional(),
7
+ nextId: joi.string().optional().allow( '' ),
8
8
  limit: joi.number().optional(),
9
9
  },
10
10
  );
@@ -15,7 +15,7 @@ export const getFileValid = {
15
15
 
16
16
  export const saveDraftSchema = joi.object(
17
17
  {
18
- userCommands: joi.string().optional(),
18
+ userCommands: joi.string().optional().allow( '' ),
19
19
  storeId: joi.string().required(),
20
20
  auditId: joi.string().required(),
21
21
  auditType: joi.string().required(),
@@ -60,15 +60,15 @@ export const saveValid = {
60
60
  body: saveSchema,
61
61
  };
62
62
 
63
- export const getQueueDetailListSchema = joi.object(
63
+ export const workSpaceSchema = joi.object(
64
64
  {
65
65
  searchValue: joi.string().optional(),
66
66
  offset: joi.string().optional(),
67
67
  limit: joi.number().optional(),
68
- export: joi.number().optional(),
68
+ isExport: joi.boolean().optional(),
69
69
  },
70
70
  );
71
71
 
72
- export const getQueueDetailListValid = {
73
- query: getQueueDetailListSchema,
72
+ export const workSpaceValid = {
73
+ query: workSpaceSchema,
74
74
  };
@@ -1,8 +1,8 @@
1
1
  import express from 'express';
2
2
  import { isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { getAuditFile, getDraftedData, getQueueDetailList, save, saveDraft } from '../controllers/audit.controllers.js';
5
- import { getDraftedDataValid, getFileValid, getQueueDetailListValid, saveDraftValid, saveValid } from '../dtos/audit.dtos.js';
4
+ import { getAuditFile, getDraftedData, save, saveDraft, workSpace } from '../controllers/audit.controllers.js';
5
+ import { getDraftedDataValid, getFileValid, saveDraftValid, saveValid, workSpaceValid } from '../dtos/audit.dtos.js';
6
6
 
7
7
  export const auditRouter = express.Router();
8
8
 
@@ -10,6 +10,6 @@ auditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ),
10
10
  auditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
11
11
  auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
12
12
  auditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
13
- auditRouter.get( '/get-queue-detail-list', isAllowedSessionHandler, validate( getQueueDetailListValid ), getQueueDetailList );
13
+ auditRouter.get( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
14
14
 
15
15
  export default auditRouter;
@@ -7,3 +7,7 @@ export function updateOneStoreAudit( query, record ) {
7
7
  export function createStoreAudit( record ) {
8
8
  return storeAuditModel.create( record );
9
9
  }
10
+
11
+ export function aggregateStoreAudit( query ) {
12
+ return storeAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
13
+ }