tango-app-api-audit 3.4.68-beta.3 → 3.4.68-beta.5

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.68-beta.3",
3
+ "version": "3.4.68-beta.5",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -147,7 +147,7 @@ export async function getList( req, res ) {
147
147
  'bool': search,
148
148
  },
149
149
  'sort': [
150
- { createdAt: { order: 'desc' } },
150
+ { 'storeName.keyword': { order: 'desc' } },
151
151
  ],
152
152
  };
153
153
  }
@@ -164,7 +164,7 @@ export async function getList( req, res ) {
164
164
  const chunkedMappingData = await chunkArray( searchValue, 10 );
165
165
  const promises = chunkedMappingData.map( async ( chunk ) => {
166
166
  const exportData = [];
167
- chunk.forEach( async ( element ) => {
167
+ for ( const element of chunk ) {
168
168
  const testDuration = element?._source?.testDuration;
169
169
  const minutes = Math.floor( testDuration / 60 );
170
170
  const seconds = testDuration % 60;
@@ -200,11 +200,11 @@ export async function getList( req, res ) {
200
200
  'Visitor Type': element?._source?.visitorsType,
201
201
  'Test Duration': duration || '',
202
202
  'Audit Status': element?._source?.auditStatus || '',
203
- 'Audited By': userName.userName || '',
203
+ 'Audited By': userName?.userName || '',
204
204
 
205
205
  } );
206
206
  }
207
- } );
207
+ }
208
208
  return exportData;
209
209
  } );
210
210
  const mappedArrays = await Promise.all( promises );
@@ -590,6 +590,94 @@ export async function save( req, res ) {
590
590
  }
591
591
  }
592
592
 
593
+ export async function cancel( req, res ) {
594
+ try {
595
+ const inputData = req.body;
596
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
597
+
598
+ let searchFilter =[
599
+ {
600
+ 'term': {
601
+ 'queueId.keyword': inputData?.fileId,
602
+ },
603
+
604
+ },
605
+ {
606
+ 'term': {
607
+ 'type.keyword': inputData?.type,
608
+ },
609
+
610
+ },
611
+
612
+ {
613
+ 'term': {
614
+ 'auditStatus.keyword': 'In-Progress',
615
+ },
616
+ },
617
+ ];
618
+ if ( inputData?.type == 'remote' ) {
619
+ searchFilter =[
620
+ {
621
+ 'term': {
622
+ 'engagementId.keyword': inputData?.fileId,
623
+ },
624
+
625
+ },
626
+ {
627
+ 'term': {
628
+ 'type.keyword': inputData?.type,
629
+ },
630
+
631
+ },
632
+ {
633
+ 'term': {
634
+ 'userId.keyword': req?.user?._id,
635
+ },
636
+ },
637
+ {
638
+ 'term': {
639
+ 'auditStatus.keyword': 'In-Progress',
640
+ },
641
+ },
642
+ ];
643
+ }
644
+
645
+ let searchQuery={
646
+ 'size': 1,
647
+ 'query': {
648
+ 'bool': {
649
+ 'must': searchFilter,
650
+ },
651
+ },
652
+ };
653
+ const getOutput = await getOpenSearchData( openSearch.EyeTestOutput, searchQuery );
654
+ logger.info( { getOutput: getOutput } );
655
+ const output = getOutput?.body?.hits?.hits?.length > 0 ? getOutput?.body?.hits?.hits[0] : null;
656
+ if ( !output ) {
657
+ return res.sendError( 'No saved records found', 400 );
658
+ }
659
+ const record1 ={
660
+
661
+ auditStatus: 'Skipped',
662
+ endTime: dayjs().tz( 'Asia/Kolkata' ),
663
+
664
+ };
665
+ const record2 ={
666
+
667
+ auditStatus: 'Yet-to-Audit',
668
+ endTime: dayjs().tz( 'Asia/Kolkata' ),
669
+
670
+ };
671
+ await updateOpenSearchData( openSearch.EyeTestOutput, output?._id, { doc: record1 } );
672
+ await updateOpenSearchData( openSearch.EyeTestInput, inputData.id, { doc: record2 } );
673
+ return res.sendSuccess( 'The file has canceled ' );
674
+ } catch ( error ) {
675
+ const err = error.message || 'Internal Server Error';
676
+ logger.error( { message: error, data: req.params, function: 'eyetestAudit-controller-cancel' } );
677
+ return res.sendError( err, 500 );
678
+ }
679
+ }
680
+
593
681
  export async function getFileHistory( req, res ) {
594
682
  try {
595
683
  const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
@@ -606,7 +694,11 @@ export async function getFileHistory( req, res ) {
606
694
  'queueId.keyword': inputData.id,
607
695
  },
608
696
  },
609
-
697
+ {
698
+ 'terms': {
699
+ 'auditStatus.keyword': [ 'Audited', 'Re-Audited' ],
700
+ },
701
+ },
610
702
  ],
611
703
  },
612
704
  },
@@ -622,7 +714,11 @@ export async function getFileHistory( req, res ) {
622
714
  'engagementId.keyword': inputData.id,
623
715
  },
624
716
  },
625
-
717
+ {
718
+ 'terms': {
719
+ 'auditStatus.keyword': [ 'Audited', 'Re-Audited' ],
720
+ },
721
+ },
626
722
  ],
627
723
  },
628
724
  },
@@ -634,13 +730,14 @@ export async function getFileHistory( req, res ) {
634
730
  let sourcesArray = resposnse.body.hits.hits.map( ( hit ) => hit );
635
731
  let outputData=[];
636
732
  for ( let data of sourcesArray ) {
733
+ // console.log( data._source.endTime );
637
734
  let findUser= await findOneUser( { _id: new mongoose.Types.ObjectId( data._source.userId ) } );
638
735
  outputData.push( {
639
736
  _id: data._id,
640
737
  userId: data._source.userId,
641
738
  userName: findUser.userName,
642
739
  Date: dayjs( data._source.endTime ).format( 'DD/MM/YYYY' ),
643
- Time: dayjs( data._source.endTime ).format( 'HH:MM:ss' ),
740
+ Time: data._source.endTime?new Date( data._source.endTime ).toLocaleTimeString( 'en-IN', { hour12: false } ):'-',
644
741
  } );
645
742
  }
646
743
 
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getListSchema, getFileSchema, getFileHistorySchema, userAuditedDataSchema, viewFileSchema, saveSchema } from '../dtos/eyeTestAudit.dtos.js';
2
+ import { getListSchema, getFileSchema, getFileHistorySchema, userAuditedDataSchema, viewFileSchema, saveSchema, cancelSchema } from '../dtos/eyeTestAudit.dtos.js';
3
3
 
4
4
  export const eyeTestAuditDocs = {
5
5
 
@@ -93,6 +93,28 @@ export const eyeTestAuditDocs = {
93
93
  },
94
94
  },
95
95
 
96
+ '/v3/eye-test-audit/cancel': {
97
+ post: {
98
+ tags: [ 'Eye Test Audit' ],
99
+ description: 'cancel eytest audit',
100
+ operationId: 'cancel',
101
+ requestBody: {
102
+ content: {
103
+ 'application/json': {
104
+ schema: j2s( cancelSchema ).swagger,
105
+ },
106
+ },
107
+ },
108
+ responses: {
109
+ 200: { description: 'Successful' },
110
+ 401: { description: 'Unauthorized User' },
111
+ 422: { description: 'Field Error' },
112
+ 500: { description: 'Server Error' },
113
+ 204: { description: 'Not Found' },
114
+ },
115
+ },
116
+ },
117
+
96
118
  '/v3/eye-test-audit/get-file-history/{id}': {
97
119
  get: {
98
120
  tags: [ 'Eye Test Audit' ],
@@ -53,6 +53,17 @@ export const saveValid = {
53
53
  };
54
54
 
55
55
 
56
+ export const cancelSchema = joi.object( {
57
+ type: joi.string().required(),
58
+ fileId: joi.string().required(),
59
+ id: joi.string().required(),
60
+ } );
61
+
62
+ export const cancelValid = {
63
+ body: cancelSchema,
64
+ };
65
+
66
+
56
67
  export const getFileHistorySchema = joi.object( {
57
68
  id: joi.string().required(),
58
69
  type: joi.string().required(),
@@ -1,8 +1,8 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
3
  import { accessVerification } from 'tango-app-api-middleware';
4
- import { getFileHistoryValid, getFileValid, getListValid, saveValid, userAuditedDataValid, viewFileValid } from '../dtos/eyeTestAudit.dtos.js';
5
- import { getFile, getFileHistory, getList, save, userAuditedData, viewFile } from '../controllers/eyeTestAudit.controllers.js';
4
+ import { cancelValid, getFileHistoryValid, getFileValid, getListValid, saveValid, userAuditedDataValid, viewFileValid } from '../dtos/eyeTestAudit.dtos.js';
5
+ import { cancel, getFile, getFileHistory, getList, save, userAuditedData, viewFile } from '../controllers/eyeTestAudit.controllers.js';
6
6
 
7
7
  export const eyeTestAuditRouter = Router();
8
8
 
@@ -10,6 +10,7 @@ eyeTestAuditRouter.post( '/get-list', isAllowedSessionHandler, accessVerificatio
10
10
  eyeTestAuditRouter.get( '/view-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( viewFileValid ), viewFile );
11
11
  eyeTestAuditRouter.get( '/get-file/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileValid ), getFile );
12
12
  eyeTestAuditRouter.post( '/save', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( saveValid ), save );
13
+ eyeTestAuditRouter.post( '/cancel', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( cancelValid ), cancel );
13
14
  eyeTestAuditRouter.get( '/get-file-history/:id/:type', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileHistoryValid ), getFileHistory );
14
15
  eyeTestAuditRouter.get( '/user-audited-data/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( userAuditedDataValid ), userAuditedData );
15
16