tango-app-api-audit 3.4.66 → 3.4.68-beta.0

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/index.js CHANGED
@@ -6,7 +6,9 @@ import { auditWalletRouter } from './src/routes/auditWallet.routes.js';
6
6
  import { auditDocs } from './src/docs/audit.docs.js';
7
7
  import { traxAuditDocs } from './src/docs/traxAudit.docs.js';
8
8
  import { auditWalletDocs } from './src/docs/auditWallet.docs.js';
9
+ import { eyeTestAuditRouter } from './src/routes/eyeTestAudit.routes.js';
10
+ import { eyeTestAuditDocs } from './src/docs/eyeTestAudit.docs.js';
9
11
 
10
- export { auditRouter, auditDocs, traxAuditRouter, traxAuditDocs, auditWalletRouter, auditWalletDocs };
12
+ export { auditRouter, auditDocs, traxAuditRouter, traxAuditDocs, auditWalletRouter, auditWalletDocs, eyeTestAuditRouter, eyeTestAuditDocs };
11
13
 
12
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.66",
3
+ "version": "3.4.68-beta.0",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,224 @@
1
+ import { getOpenSearchData, insertOpenSearchData, getOpenSearchById, logger } from 'tango-app-api-middleware';
2
+ import { findOneUser } from '../service/user.service.js';
3
+ import mongoose from 'mongoose';
4
+ import dayjs from 'dayjs';
5
+
6
+ export async function getList( req, res ) {
7
+ try {
8
+ const inputData = req.body;
9
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
10
+ const limit = inputData.limit || 10;
11
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
12
+
13
+
14
+ let filter= [
15
+ {
16
+ 'range': {
17
+ 'date': {
18
+ 'gte': new Date( inputData.fromDate ),
19
+ 'lte': new Date( inputData.toDate ),
20
+ },
21
+ },
22
+ },
23
+
24
+ ];
25
+ let search ={
26
+ 'must': filter,
27
+ };
28
+
29
+ if ( inputData.visitorsType && inputData.visitorsType.lenght > 0 ) {
30
+ filter.push( {
31
+
32
+ 'terms': {
33
+ 'visitorsType.keyword': inputData.visitorsType,
34
+ },
35
+
36
+ } );
37
+ }
38
+
39
+ if ( inputData.storeId && inputData.storeId.lenght > 0 ) {
40
+ filter.push( {
41
+
42
+ 'terms': {
43
+ 'storeId.keyword': inputData.storeId,
44
+ },
45
+
46
+ } );
47
+ }
48
+
49
+ if ( inputData.searchValue && inputData.searchValue !== '' ) {
50
+ search ={
51
+ 'must': filter,
52
+ 'should': [
53
+ {
54
+ 'wildcard': {
55
+ 'storeName.keyword': {
56
+ 'value': `*${inputData.searchValue}*`,
57
+ },
58
+ },
59
+ },
60
+ {
61
+ 'wildcard': {
62
+ 'storeId.keyword': {
63
+ 'value': `*${inputData.searchValue}*`,
64
+ },
65
+ },
66
+ },
67
+ {
68
+ 'wildcard': {
69
+ 'engagementId.keyword': {
70
+ 'value': `*${inputData.searchValue}*`,
71
+ },
72
+ },
73
+ },
74
+ {
75
+ 'wildcard': {
76
+ 'queueId.keyword': {
77
+ 'value': `*${inputData.searchValue}*`,
78
+ },
79
+ },
80
+ },
81
+ {
82
+ 'wildcard': {
83
+ 'optumId.keyword': {
84
+ 'value': `*${inputData.engagementId}*`,
85
+ },
86
+ },
87
+ },
88
+ {
89
+ 'wildcard': {
90
+ 'visitorsType.keyword': {
91
+ 'value': `*${inputData.searchValue}*`,
92
+ },
93
+ },
94
+ },
95
+ {
96
+ 'wildcard': {
97
+ 'auditStatus.keyword': {
98
+ 'value': `*${inputData.searchValue}*`,
99
+ },
100
+ },
101
+ },
102
+ ],
103
+ 'minimum_should_match': 1,
104
+ };
105
+ }
106
+
107
+ let searchQuery={
108
+ 'from': offset,
109
+ 'size': limit,
110
+ 'query': {
111
+ 'bool': search,
112
+ },
113
+ };
114
+ const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
115
+ const count = result?.body?.hits?.total?.value;
116
+ if ( !count || count == 0 ) {
117
+ return res.sendError( 'No data found', 204 );
118
+ }
119
+ const searchValue = result?.body?.hits?.hits;
120
+ if ( !searchValue || searchValue?.length == 0 ) {
121
+ return res.sendError( 'No data found', 204 );
122
+ }
123
+ return res.sendSuccess( { result: searchValue, count: count } );
124
+ } catch ( error ) {
125
+ const err = error.message || 'Internal Server Error';
126
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-getList' } );
127
+ return res.sendError( err, 500 );
128
+ }
129
+ }
130
+
131
+ export async function getFile( req, res ) {
132
+ try {
133
+ const inputData = req.params;
134
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
135
+ const result =await insertOpenSearchData( openSearch.EyeTestOutput, physicalRecord );
136
+ return res.sendSuccess( { result: result, inputData: inputData, record: record } );
137
+ } catch ( error ) {
138
+ const err = error.message || 'Internal Server Error';
139
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-getFile' } );
140
+ return res.sendError( err, 500 );
141
+ }
142
+ }
143
+
144
+ export async function getFileHistory( req, res ) {
145
+ try {
146
+ const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
147
+ const inputData = req.params;
148
+ let Query = {};
149
+ if ( inputData.type==='physical' ) {
150
+ Query = {
151
+ 'size': 100,
152
+ 'query': {
153
+ 'bool': {
154
+ 'must': [
155
+ {
156
+ 'term': {
157
+ 'queueId.keyword': inputData.id,
158
+ },
159
+ },
160
+
161
+ ],
162
+ },
163
+ },
164
+ };
165
+ } else {
166
+ Query = {
167
+ 'size': 100,
168
+ 'query': {
169
+ 'bool': {
170
+ 'must': [
171
+ {
172
+ 'term': {
173
+ 'engagementId.keyword': inputData.id,
174
+ },
175
+ },
176
+
177
+ ],
178
+ },
179
+ },
180
+ };
181
+ };
182
+
183
+ const resposnse = await getOpenSearchData( parsedOpenSearch.EyeTestOutput, Query );
184
+ if ( resposnse.body.hits.hits.length > 0 ) {
185
+ let sourcesArray = resposnse.body.hits.hits.map( ( hit ) => hit );
186
+ let outputData=[];
187
+ for ( let data of sourcesArray ) {
188
+ let findUser= await findOneUser( { _id: new mongoose.Types.ObjectId( data._source.userId ) } );
189
+ outputData.push( {
190
+ _id: data._id,
191
+ userId: data._source.userId,
192
+ userName: findUser.userName,
193
+ Date: dayjs( data._source.endTime ).format( 'DD/MM/YYYY' ),
194
+ Time: dayjs( data._source.endTime ).format( 'HH:MM:ss' ),
195
+ } );
196
+ }
197
+
198
+ return res.sendSuccess( { result: outputData } );
199
+ } else {
200
+ return res.sendError( 'No data found', 204 );
201
+ }
202
+ } catch ( error ) {
203
+ const err = error.message || 'Internal Server Error';
204
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-getFileHistory' } );
205
+ return res.sendError( err, 500 );
206
+ }
207
+ }
208
+
209
+ export async function userAuditedData( req, res ) {
210
+ try {
211
+ const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
212
+ const inputData = req.params;
213
+ const resposnse = await getOpenSearchById( parsedOpenSearch.EyeTestOutput, inputData.id );
214
+ if ( resposnse.body&&resposnse.body._source ) {
215
+ return res.sendSuccess( { result: resposnse.body._source.steps } );
216
+ } else {
217
+ return res.sendError( 'No data found', 204 );
218
+ }
219
+ } catch ( error ) {
220
+ const err = error.message || 'Internal Server Error';
221
+ logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-userAuditedData' } );
222
+ return res.sendError( err, 500 );
223
+ }
224
+ }
@@ -1739,6 +1739,26 @@ export async function saveBinary( req, res ) {
1739
1739
  } else {
1740
1740
  await insertOpenSearchData( openSearch.traxDetectionOutput, anomalyOutput );
1741
1741
  }
1742
+ if ( inputData.answer==='approved' ) {
1743
+ let usersList=JSON.parse( process.env.SES );
1744
+ let emails =usersList.suspeciousEmails.split( ',' );
1745
+
1746
+ for ( let user of emails ) {
1747
+ let notificationData= {
1748
+ 'title': 'Suspecious Activity Detected',
1749
+ 'description': `${getData?.sqs?.Body?.zone_name} at ${getStore2?.storeName}- Immediate action required`,
1750
+ 'storeId': inputData.storeId,
1751
+ 'type': 'suspiciousactivity',
1752
+ 'date': inputData.fileDate,
1753
+ 'clientId': req.userAudit?.clientId,
1754
+ 'email': user,
1755
+ };
1756
+ await axios.post( `${url.apiDomain}/v3/trax/internalAPI/sendAiPushNotification`, notificationData, { headers: {
1757
+ 'Content-Type': 'application/json',
1758
+ 'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f55' },
1759
+ } );
1760
+ }
1761
+ }
1742
1762
 
1743
1763
  const logData4 = {
1744
1764
  userId: req.user._id,
@@ -0,0 +1,102 @@
1
+ import j2s from 'joi-to-swagger';
2
+ import { getListSchema, getFileSchema, getFileHistorySchema, userAuditedDataSchema } from '../dtos/eyeTestAudit.dtos.js';
3
+
4
+ export const eyeTestAuditDocs = {
5
+
6
+ '/v3/eye-test-audit/get-list': {
7
+ post: {
8
+ tags: [ 'Eye Test Audit' ],
9
+ description: 'Get list of files',
10
+ operationId: 'get-list',
11
+ requestBody: {
12
+ content: {
13
+ 'application/json': {
14
+ schema: j2s( getListSchema ).swagger,
15
+ },
16
+ },
17
+ },
18
+ responses: {
19
+ 200: { description: 'Successful' },
20
+ 401: { description: 'Unauthorized User' },
21
+ 422: { description: 'Field Error' },
22
+ 500: { description: 'Server Error' },
23
+ 204: { description: 'Not Found' },
24
+ },
25
+ },
26
+ },
27
+
28
+ '/v3/eye-test-audit/get-file/{id}/{type}': {
29
+ get: {
30
+ tags: [ 'Eye Test Audit' ],
31
+ description: 'Get a file via Open Serach',
32
+ operationId: 'get-file',
33
+ parameters: [
34
+ {
35
+ in: 'path',
36
+ name: 'id',
37
+ scema: j2s( getFileSchema ).swagger,
38
+ require: true,
39
+ },
40
+ {
41
+ in: 'path',
42
+ name: 'type',
43
+ scema: j2s( getFileSchema ).swagger,
44
+ require: true,
45
+ },
46
+ ],
47
+ responses: {
48
+ 200: { description: 'Successful' },
49
+ 401: { description: 'Unauthorized User' },
50
+ 422: { description: 'Field Error' },
51
+ 500: { description: 'Server Error' },
52
+ 204: { description: 'Not Found' },
53
+ },
54
+ },
55
+ },
56
+
57
+ '/v3/eye-test-audit/get-file-history/{id}': {
58
+ get: {
59
+ tags: [ 'Eye Test Audit' ],
60
+ description: 'Get a file history via Open Serach',
61
+ operationId: 'get-file-history',
62
+ parameters: [
63
+ {
64
+ in: 'path',
65
+ name: 'id',
66
+ scema: j2s( getFileHistorySchema ).swagger,
67
+ require: true,
68
+ },
69
+ ],
70
+ responses: {
71
+ 200: { description: 'Successful' },
72
+ 401: { description: 'Unauthorized User' },
73
+ 422: { description: 'Field Error' },
74
+ 500: { description: 'Server Error' },
75
+ 204: { description: 'Not Found' },
76
+ },
77
+ },
78
+ },
79
+
80
+ '/v3/eye-test-audit/user-audited-data/{id}': {
81
+ get: {
82
+ tags: [ 'Eye Test Audit' ],
83
+ description: `Get a user's audited file`,
84
+ operationId: 'user-audited-data',
85
+ parameters: [
86
+ {
87
+ in: 'path',
88
+ name: 'id',
89
+ scema: j2s( userAuditedDataSchema ).swagger,
90
+ require: true,
91
+ },
92
+ ],
93
+ responses: {
94
+ 200: { description: 'Successful' },
95
+ 401: { description: 'Unauthorized User' },
96
+ 422: { description: 'Field Error' },
97
+ 500: { description: 'Server Error' },
98
+ 204: { description: 'Not Found' },
99
+ },
100
+ },
101
+ },
102
+ };
@@ -0,0 +1,48 @@
1
+ import joi from 'joi';
2
+
3
+ export const getListSchema = joi.object(
4
+ {
5
+ fromDate: joi.string().required(),
6
+ toDate: joi.string().required(),
7
+ type: joi.string().required(),
8
+ demographics: joi.array().optional(),
9
+ storeId: joi.array().optional(),
10
+ limit: joi.number().optional(),
11
+ offset: joi.number().optional(),
12
+ searchValue: joi.string().optional().allow( '' ),
13
+ isExport: joi.boolean().optional(),
14
+ },
15
+ );
16
+
17
+ export const getListValid = {
18
+ body: getListSchema,
19
+ };
20
+
21
+
22
+ export const getFileSchema = joi.object( {
23
+ id: joi.string().required(),
24
+ type: joi.string().required(),
25
+ } );
26
+
27
+ export const getFileValid = {
28
+ params: getFileSchema,
29
+ };
30
+
31
+ export const getFileHistorySchema = joi.object( {
32
+ id: joi.string().required(),
33
+ type: joi.string().required(),
34
+ } );
35
+
36
+ export const getFileHistoryValid = {
37
+ params: getFileHistorySchema,
38
+ };
39
+
40
+ export const userAuditedDataSchema = joi.object( {
41
+ id: joi.string().required(),
42
+ } );
43
+
44
+ export const userAuditedDataValid = {
45
+ params: userAuditedDataSchema,
46
+ };
47
+
48
+
@@ -0,0 +1,15 @@
1
+ import { Router } from 'express';
2
+ import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
+ import { accessVerification } from 'tango-app-api-middleware';
4
+ import { getFileHistoryValid, getFileValid, getListValid, userAuditedDataValid } from '../dtos/eyeTestAudit.dtos.js';
5
+ import { getFile, getFileHistory, getList, userAuditedData } from '../controllers/eyeTestAudit.controllers.js';
6
+
7
+ export const eyeTestAuditRouter = Router();
8
+
9
+ eyeTestAuditRouter.post( '/get-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getListValid ), getList );
10
+ eyeTestAuditRouter.get( '/get-file/:id/:type', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileValid ), getFile );
11
+ eyeTestAuditRouter.get( '/get-file-history/:id/:type', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( getFileHistoryValid ), getFileHistory );
12
+ eyeTestAuditRouter.get( '/user-audited-data/:id', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( userAuditedDataValid ), userAuditedData );
13
+
14
+
15
+ export default eyeTestAuditRouter;