tango-app-api-audit 1.0.11 → 1.0.12
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.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"mongodb": "^6.7.0",
|
|
24
24
|
"nodemon": "^3.1.3",
|
|
25
25
|
"swagger-ui-express": "^5.0.1",
|
|
26
|
-
"tango-api-schema": "^2.0.
|
|
26
|
+
"tango-api-schema": "^2.0.121",
|
|
27
27
|
"tango-app-api-middleware": "^3.1.24",
|
|
28
28
|
"winston": "^3.13.0",
|
|
29
29
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chunkArray, download, getJsonFileData,
|
|
1
|
+
import { chunkArray, download, getJsonFileData, 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';
|
|
@@ -9,10 +9,12 @@ import { listQueue, sqsReceive } from 'tango-app-api-middleware/src/utils/aws/sq
|
|
|
9
9
|
import { aggregateStoreAudit, createStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
|
|
10
10
|
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
11
11
|
import _ from 'lodash';
|
|
12
|
+
import { createAuditLog, findOneAuditLog } from '../service/auditLog.service.js';
|
|
12
13
|
|
|
13
14
|
export async function getAuditFile( req, res ) {
|
|
14
15
|
try {
|
|
15
16
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
17
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
16
18
|
const inputData = req.query;
|
|
17
19
|
const data = await getUTC( new Date(), new Date() );
|
|
18
20
|
const start = data.start;
|
|
@@ -84,64 +86,65 @@ export async function getAuditFile( req, res ) {
|
|
|
84
86
|
}
|
|
85
87
|
break;
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
89
|
+
case 'drafted':
|
|
90
|
+
logger.info( 'userDetails drafted', { inputData } );
|
|
91
|
+
const log = await findOneAuditLog( {
|
|
92
|
+
userId: userDetails[0].userId,
|
|
93
|
+
fileDate: userDetails[0].fileDate,
|
|
94
|
+
storeId: userDetails[0].storeId,
|
|
95
|
+
totalCount: userDetails[0].beforeCount,
|
|
96
|
+
}, {}, { createdAt: -1 } );
|
|
97
|
+
if ( log.length == 0 ) {
|
|
98
|
+
await updateOneUserAudit( { _id: userDetails[0]._id }, { $set: { isDraft: false, auditStatus: 'skipped' } } );
|
|
99
|
+
logger.info( 'audit update in drafted', { _id: userDetails[0]._id, isDraft: false, auditStatus: 'skipped' } );
|
|
100
|
+
return res.sendError( 'User saved data has been deleted', 204 );
|
|
101
|
+
}
|
|
102
|
+
const file = {
|
|
103
|
+
auditId: userDetails[0]._id,
|
|
104
|
+
store_id: userDetails[0].storeId,
|
|
105
|
+
file_date: userDetails[0].fileDate,
|
|
106
|
+
type: userDetails[0].auditType,
|
|
107
|
+
queueName: log[0].queueName,
|
|
108
|
+
userId: log[0].userId,
|
|
109
|
+
};
|
|
110
|
+
const result = {
|
|
111
|
+
junk: log[0].junk,
|
|
112
|
+
junk_count: log[0].junkCount,
|
|
113
|
+
employee: log[0].employee,
|
|
114
|
+
employee_count: log[0].employeeCount,
|
|
115
|
+
customer: log[0].customer,
|
|
116
|
+
customer_count: log[0].customerCount,
|
|
117
|
+
retag_image: log[0].retagImage,
|
|
118
|
+
retag_count: log[0].retagCount,
|
|
119
|
+
total_count: log[0].totalCount,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const userdata = await findOneUser( { _id: log[0].userId } );
|
|
123
|
+
if ( !inputData.nextId || inputData.nextId === '' || inputData.nextId == null ) {
|
|
124
|
+
const logData = {
|
|
125
|
+
userId: log[0].userId,
|
|
126
|
+
userName: userdata.name,
|
|
127
|
+
logType: 'audit',
|
|
128
|
+
logSubType: 'auditStart',
|
|
129
|
+
logData: {
|
|
130
|
+
file_date: userDetails[0].fileDate,
|
|
131
|
+
auditType: userDetails[0].auditType,
|
|
132
|
+
storeId: userDetails[0].storeId,
|
|
133
|
+
clientName: log[0].queueName,
|
|
134
|
+
auditId: userDetails[0]._id,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
logger.info( { logData: logData } );
|
|
138
|
+
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
139
|
+
// await savelogs( logData ); Note : insert to os
|
|
140
|
+
}
|
|
141
|
+
return res.sendSuccess( {
|
|
142
|
+
result: result,
|
|
143
|
+
count: log[0].totalCount,
|
|
144
|
+
file: file,
|
|
145
|
+
isDraft: userDetails[0].isDraft,
|
|
146
|
+
} );
|
|
147
|
+
break;
|
|
145
148
|
|
|
146
149
|
default:
|
|
147
150
|
msg = {
|
|
@@ -808,9 +811,8 @@ export async function saveDraft( req, res ) {
|
|
|
808
811
|
},
|
|
809
812
|
};
|
|
810
813
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
811
|
-
logger.info( { logData: logData } ); // need to insert to os
|
|
812
814
|
}
|
|
813
|
-
await
|
|
815
|
+
await createAuditLog( inputData );
|
|
814
816
|
await updateOneUserAudit( userQuery, userRecord );
|
|
815
817
|
await updateOneStoreAudit( storeQuery, storeRecord );
|
|
816
818
|
return res.sendSuccess( { result: 'The file has been drafted successfully' } );
|
|
@@ -823,46 +825,16 @@ export async function saveDraft( req, res ) {
|
|
|
823
825
|
|
|
824
826
|
export async function getDraftedData( req, res ) {
|
|
825
827
|
try {
|
|
826
|
-
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
827
828
|
const inputData = req.query;
|
|
828
|
-
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
'bool': {
|
|
834
|
-
'must': [
|
|
835
|
-
{
|
|
836
|
-
'term': {
|
|
837
|
-
'fileDate.keyword': inputData.fileDate,
|
|
838
|
-
},
|
|
839
|
-
},
|
|
840
|
-
{
|
|
841
|
-
'term': {
|
|
842
|
-
'storeId.keyword': inputData.storeId,
|
|
843
|
-
},
|
|
844
|
-
},
|
|
845
|
-
{
|
|
846
|
-
'term': {
|
|
847
|
-
'userId.keyword': req.user._id,
|
|
848
|
-
},
|
|
849
|
-
},
|
|
850
|
-
|
|
851
|
-
],
|
|
852
|
-
|
|
853
|
-
},
|
|
854
|
-
},
|
|
829
|
+
const userId = inputData.userId || req.user._id;
|
|
830
|
+
const query={
|
|
831
|
+
fileDate: inputData.fileDate,
|
|
832
|
+
storeId: inputData.storeId,
|
|
833
|
+
userId: userId,
|
|
855
834
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
'timestamp': {
|
|
859
|
-
'order': 'desc',
|
|
860
|
-
},
|
|
861
|
-
},
|
|
862
|
-
],
|
|
835
|
+
};
|
|
836
|
+
const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
863
837
|
|
|
864
|
-
} );
|
|
865
|
-
const result = getLog?.body?.hits?.hits;
|
|
866
838
|
if ( result.length ==0 ) {
|
|
867
839
|
return res.sendError( 'No Data Found', 500 );
|
|
868
840
|
}
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import auditLogsModel from 'tango-api-schema/schema/auditLogs.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function createAuditLog( record ) {
|
|
5
|
+
return auditLogsModel.create( record );
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function findOneAuditLog( query, fields={}, sort={ createdAt: -1 }, limit=10 ) {
|
|
9
|
+
return auditLogsModel.findOne( query, fields ).sort( sort ).limit( limit );
|
|
10
|
+
}
|