tango-app-api-audit 3.4.0-alpha.1 → 3.4.0-alpha.10

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.
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getFileSchema } from '../dtos/traxAudit.dtos.js';
2
+ import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema } from '../dtos/traxAudit.dtos.js';
3
3
 
4
4
  export const traxAuditDocs = {
5
5
 
@@ -43,4 +43,229 @@ export const traxAuditDocs = {
43
43
  },
44
44
  },
45
45
  },
46
+
47
+ '/v3/trax-audit/work-space': {
48
+ post: {
49
+ tags: [ 'Trax Audit' ],
50
+ description: 'queue wise info of audit files ',
51
+ operationId: 'work-space',
52
+ requestBody: {
53
+ content: {
54
+ 'application/json': {
55
+ schema: j2s( workSpaceSchema ).swagger,
56
+ },
57
+ },
58
+ },
59
+ responses: {
60
+ 200: { description: 'Successful' },
61
+ 401: { description: 'Unauthorized User' },
62
+ 422: { description: 'Field Error' },
63
+ 500: { description: 'Server Error' },
64
+ 204: { description: 'Not Found' },
65
+ },
66
+ },
67
+ },
68
+
69
+ '/v3/trax-audit/save-binary-audit': {
70
+ post: {
71
+ tags: [ 'Trax Audit' ],
72
+ description: 'Save binay data type',
73
+ operationId: 'save-binary-audit',
74
+ parameters: {},
75
+ requestBody: {
76
+ content: {
77
+ 'application/json': {
78
+ schema: j2s( saveSchema ).swagger,
79
+ },
80
+ },
81
+ },
82
+ responses: {
83
+ 200: { description: 'Successful' },
84
+ 401: { description: 'Unauthorized User' },
85
+ 422: { description: 'Field Error' },
86
+ 500: { description: 'Server Error' },
87
+ 204: { description: 'Not Found' },
88
+ },
89
+ },
90
+ },
91
+
92
+ '/v3/trax-audit/metrics/user-audit-history': {
93
+ post: {
94
+ tags: [ 'Trax Audit' ],
95
+ description: `Get list of user wise audit user details with date range`,
96
+ operationId: 'metrics/user-audit-history',
97
+ parameters: {},
98
+ requestBody: {
99
+ content: {
100
+ 'application/json': {
101
+ schema: j2s( userAuditHistorySchema ).swagger,
102
+ },
103
+ },
104
+ },
105
+ responses: {
106
+ 200: { description: 'Successful' },
107
+ 401: { description: 'Unauthorized User' },
108
+ 422: { description: 'Field Error' },
109
+ 500: { description: 'Server Error' },
110
+ 204: { description: 'Not Found' },
111
+ },
112
+ },
113
+ },
114
+ '/v3/trax-audit/metrics/client-metrics': {
115
+ post: {
116
+ tags: [ 'Trax Audit' ],
117
+ description: `Get list of client wise details with date range`,
118
+ operationId: 'metrics/client-metrics',
119
+ parameters: {},
120
+ requestBody: {
121
+ content: {
122
+ 'application/json': {
123
+ schema: j2s( clientMetricsSchema ).swagger,
124
+ },
125
+ },
126
+ },
127
+ responses: {
128
+ 200: { description: 'Successful' },
129
+ 401: { description: 'Unauthorized User' },
130
+ 422: { description: 'Field Error' },
131
+ 500: { description: 'Server Error' },
132
+ 204: { description: 'Not Found' },
133
+ },
134
+ },
135
+ },
136
+
137
+ '/v3/trax-audit/metrics/store-metrics': {
138
+ post: {
139
+ tags: [ 'Trax Audit' ],
140
+ description: `Get list of store wise details with date range and client Id`,
141
+ operationId: 'metrics/store-metrics',
142
+ parameters: {},
143
+ requestBody: {
144
+ content: {
145
+ 'application/json': {
146
+ schema: j2s( storeMetricsSchema ).swagger,
147
+ },
148
+ },
149
+ },
150
+ responses: {
151
+ 200: { description: 'Successful' },
152
+ 401: { description: 'Unauthorized User' },
153
+ 422: { description: 'Field Error' },
154
+ 500: { description: 'Server Error' },
155
+ 204: { description: 'Not Found' },
156
+ },
157
+ },
158
+ },
159
+ '/v3/trax-audit/metrics/user-metrics': {
160
+ post: {
161
+ tags: [ 'Trax Audit' ],
162
+ description: `Get list of file wise details with date range and users`,
163
+ operationId: 'metrics/user-metrics',
164
+ parameters: {},
165
+ requestBody: {
166
+ content: {
167
+ 'application/json': {
168
+ schema: j2s( userMetricsSchema ).swagger,
169
+ },
170
+ },
171
+ },
172
+ responses: {
173
+ 200: { description: 'Successful' },
174
+ 401: { description: 'Unauthorized User' },
175
+ 422: { description: 'Field Error' },
176
+ 500: { description: 'Server Error' },
177
+ 204: { description: 'Not Found' },
178
+ },
179
+ },
180
+ },
181
+ '/v3/trax-audit/metrics/pending-summary-table': {
182
+ post: {
183
+ tags: [ 'Trax Audit' ],
184
+ description: `Get overall user taken data with some filters `,
185
+ operationId: 'metrics/pending-summary-table',
186
+ parameters: {},
187
+ requestBody: {
188
+ content: {
189
+ 'application/json': {
190
+ schema: j2s( pendingSummaryTableSchema ).swagger,
191
+ },
192
+ },
193
+ },
194
+ responses: {
195
+ 200: { description: 'Successful' },
196
+ 401: { description: 'Unauthorized User' },
197
+ 422: { description: 'Field Error' },
198
+ 500: { description: 'Server Error' },
199
+ 204: { description: 'Not Found' },
200
+ },
201
+ },
202
+ },
203
+ '/v3/trax-audit/metrics/overall-audit-summary': {
204
+ post: {
205
+ tags: [ 'Trax Audit' ],
206
+ description: `Get overall user taken data with some filters `,
207
+ operationId: 'metrics/overall-audit-summary',
208
+ parameters: {},
209
+ requestBody: {
210
+ content: {
211
+ 'application/json': {
212
+ schema: j2s( overAllAuditSummarySchema ).swagger,
213
+ },
214
+ },
215
+ },
216
+ responses: {
217
+ 200: { description: 'Successful' },
218
+ 401: { description: 'Unauthorized User' },
219
+ 422: { description: 'Field Error' },
220
+ 500: { description: 'Server Error' },
221
+ 204: { description: 'Not Found' },
222
+ },
223
+ },
224
+ },
225
+
226
+ '/v3/trax-audit/metrics/summary-split-up': {
227
+ post: {
228
+ tags: [ 'Trax Audit' ],
229
+ description: `Get overall high level audited files count splitup`,
230
+ operationId: 'metrics/summary-split-up',
231
+ parameters: {},
232
+ requestBody: {
233
+ content: {
234
+ 'application/json': {
235
+ schema: j2s( summarySplitSchema ).swagger,
236
+ },
237
+ },
238
+ },
239
+ responses: {
240
+ 200: { description: 'Successful' },
241
+ 401: { description: 'Unauthorized User' },
242
+ 422: { description: 'Field Error' },
243
+ 500: { description: 'Server Error' },
244
+ 204: { description: 'Not Found' },
245
+ },
246
+ },
247
+ },
248
+
249
+ '/v3/trax-audit/metrics/overview-table': {
250
+ post: {
251
+ tags: [ 'Trax Audit' ],
252
+ description: `Get overall user taken data with some filters `,
253
+ operationId: 'metrics/overview-table',
254
+ parameters: {},
255
+ requestBody: {
256
+ content: {
257
+ 'application/json': {
258
+ schema: j2s( overviewTableSchema ).swagger,
259
+ },
260
+ },
261
+ },
262
+ responses: {
263
+ 200: { description: 'Successful' },
264
+ 401: { description: 'Unauthorized User' },
265
+ 422: { description: 'Field Error' },
266
+ 500: { description: 'Server Error' },
267
+ 204: { description: 'Not Found' },
268
+ },
269
+ },
270
+ },
46
271
  };
@@ -148,7 +148,7 @@ export const userAuditHistorySchema = joi.object(
148
148
  dateType: joi.string().required(),
149
149
  clientId: joi.array().optional(),
150
150
  filterByStoreId: joi.array().required(),
151
- filterByModuleType: joi.array().optional(),
151
+ moduleType: joi.string().required(),
152
152
  filterByAuditType: joi.array().optional(),
153
153
  filterByStatus: joi.array().optional(),
154
154
  searchValue: joi.string().optional().allow( '' ),
@@ -170,7 +170,7 @@ export const clientMetricsSchema = joi.object(
170
170
  fromDate: joi.string().required(),
171
171
  toDate: joi.string().required(),
172
172
  searchValue: joi.string().optional().allow( '' ),
173
- filterByModuleType: joi.array().optional(),
173
+ moduleType: joi.string().required(),
174
174
  filterByClient: joi.array().required(),
175
175
  filterByStatus: joi.array().optional(),
176
176
  sortColumnName: joi.string().optional(),
@@ -195,7 +195,7 @@ export const storeMetricsSchema = joi.object(
195
195
  filterByStoreId: joi.array().optional(),
196
196
  filterByStatus: joi.array().optional(),
197
197
  filterByAuditType: joi.array().optional(),
198
- filterByModuleType: joi.array().optional(),
198
+ moduleType: joi.string().required(),
199
199
  sortColumnName: joi.string().optional(),
200
200
  sortBy: joi.number().optional(),
201
201
  limit: joi.number().optional(),
@@ -215,7 +215,7 @@ export const userMetricsSchema = joi.object(
215
215
  dateType: joi.string().required(),
216
216
  searchValue: joi.string().optional().allow( '' ),
217
217
  filterByUser: joi.array().optional(),
218
- filterByModuleType: joi.array().optional(),
218
+ moduleType: joi.string().required(),
219
219
  filterByStatus: joi.array().optional(),
220
220
  sortColumnName: joi.string().optional(),
221
221
  sortBy: joi.number().optional(),
@@ -238,7 +238,7 @@ export const pendingSummaryTableSchema = joi.object(
238
238
  offset: joi.number().optional(),
239
239
  searchValue: joi.string().optional().allow( '' ),
240
240
  filterByStatus: joi.array().required(),
241
- filterByModuleType: joi.array().optional(),
241
+ moduleType: joi.string().required(),
242
242
  filterByAuditType: joi.array().optional(),
243
243
  sortColumnName: joi.string().optional(),
244
244
  sortBy: joi.number().optional(),
@@ -259,7 +259,7 @@ export const overviewTableSchema = joi.object(
259
259
  offset: joi.number().optional(),
260
260
  searchValue: joi.string().optional().allow( '' ),
261
261
  filterByStatus: joi.array().optional(),
262
- filterByModuleType: joi.array().optional(),
262
+ moduleType: joi.string().required(),
263
263
  filterByAuditType: joi.array().optional(),
264
264
  sortColumnName: joi.string().optional(),
265
265
  sortBy: joi.number().optional(),
@@ -276,7 +276,7 @@ export const overAllAuditSummarySchema = joi.object(
276
276
  fromDate: joi.string().required(),
277
277
  toDate: joi.string().required(),
278
278
  clientId: joi.array().optional(),
279
- moduleType: joi.array().required(),
279
+ moduleType: joi.string().required(),
280
280
  },
281
281
  );
282
282
 
@@ -319,7 +319,7 @@ export const summarySplitSchema = joi.object(
319
319
  fromDate: joi.string().required(),
320
320
  toDate: joi.string().required(),
321
321
  clientId: joi.array().optional(),
322
- moduleType: joi.array().optional(),
322
+ moduleType: joi.string().required(),
323
323
  },
324
324
  );
325
325
 
@@ -68,18 +68,12 @@ export const saveSchema = joi.object(
68
68
  auditId: joi.string().required(),
69
69
  storeId: joi.string().required(),
70
70
  fileDate: joi.string().required(),
71
- auditType: joi.string().required(),
72
- moduleType: joi.string().required(),
73
- zoneName: joi.string().required(),
74
- beforeCount: joi.number().required(),
75
- junkCount: joi.number().required(),
76
- junk: joi.array().required(),
77
- employeeCount: joi.number().required(),
78
- employee: joi.array().required(),
79
- customerCount: joi.number().required(),
80
- customer: joi.array().required(),
71
+ tempId: joi.number().optional(),
81
72
  moduleType: joi.string().required(),
82
- zoneName: joi.string().required(),
73
+ question: joi.string().optional(),
74
+ streamName: joi.string().optional(),
75
+ answer: joi.string().required(),
76
+ userComments: joi.string().optional().allow( '' ),
83
77
  },
84
78
  );
85
79
 
@@ -103,3 +97,158 @@ export const workSpaceSchema = joi.object(
103
97
  export const workSpaceValid = {
104
98
  body: workSpaceSchema,
105
99
  };
100
+
101
+ export const userAuditHistorySchema = joi.object(
102
+ {
103
+ userId: joi.string().optional(),
104
+ fromDate: joi.string().required(),
105
+ toDate: joi.string().required(),
106
+ dateType: joi.string().required(),
107
+ clientId: joi.array().optional(),
108
+ filterByStoreId: joi.array().required(),
109
+ moduleType: joi.string().required(),
110
+ filterByAuditType: joi.array().optional(),
111
+ filterByStatus: joi.array().optional(),
112
+ searchValue: joi.string().optional().allow( '' ),
113
+ limit: joi.number().optional(),
114
+ offset: joi.number().optional(),
115
+ sortColumnName: joi.string().optional(),
116
+ sortBy: joi.number().optional(),
117
+ isExport: joi.boolean().optional(),
118
+
119
+ },
120
+ );
121
+
122
+ export const userAuditHistoryValid = {
123
+ body: userAuditHistorySchema,
124
+ };
125
+
126
+ export const clientMetricsSchema = joi.object(
127
+ {
128
+ fromDate: joi.string().required(),
129
+ toDate: joi.string().required(),
130
+ searchValue: joi.string().optional().allow( '' ),
131
+ moduleType: joi.string().required(),
132
+ filterByClient: joi.array().required(),
133
+ filterByStatus: joi.array().optional(),
134
+ sortColumnName: joi.string().optional(),
135
+ sortBy: joi.number().optional(),
136
+ limit: joi.number().optional(),
137
+ offset: joi.number().optional(),
138
+ isExport: joi.boolean().optional(),
139
+ },
140
+ );
141
+
142
+ export const clientMetricsValid = {
143
+ body: clientMetricsSchema,
144
+ };
145
+
146
+ export const storeMetricsSchema = joi.object(
147
+ {
148
+ fromDate: joi.string().required(),
149
+ toDate: joi.string().required(),
150
+ searchValue: joi.string().optional().allow( '' ),
151
+ filterByClientId: joi.array().required(),
152
+ filterByStoreId: joi.array().optional(),
153
+ filterByStatus: joi.array().optional(),
154
+ filterByAuditType: joi.array().optional(),
155
+ moduleType: joi.string().required(),
156
+ sortColumnName: joi.string().optional(),
157
+ sortBy: joi.number().optional(),
158
+ limit: joi.number().optional(),
159
+ offset: joi.number().optional(),
160
+ isExport: joi.boolean().optional(),
161
+ },
162
+ );
163
+
164
+ export const storeMetricsValid = {
165
+ body: storeMetricsSchema,
166
+ };
167
+ export const userMetricsSchema = joi.object(
168
+ {
169
+ fromDate: joi.string().required(),
170
+ toDate: joi.string().required(),
171
+ dateType: joi.string().required(),
172
+ searchValue: joi.string().optional().allow( '' ),
173
+ filterByUser: joi.array().optional(),
174
+ moduleType: joi.string().optional(),
175
+ filterByStatus: joi.array().optional(),
176
+ sortColumnName: joi.string().optional(),
177
+ sortBy: joi.number().optional(),
178
+ limit: joi.number().optional(),
179
+ offset: joi.number().optional(),
180
+ isExport: joi.boolean().optional(),
181
+ },
182
+ );
183
+
184
+ export const userMetricsValid = {
185
+ body: userMetricsSchema,
186
+ };
187
+
188
+ export const pendingSummaryTableSchema = joi.object(
189
+ {
190
+ fromDate: joi.string().required(),
191
+ toDate: joi.string().required(),
192
+ clientId: joi.array().optional(),
193
+ limit: joi.number().optional(),
194
+ offset: joi.number().optional(),
195
+ searchValue: joi.string().optional().allow( '' ),
196
+ filterByStatus: joi.array().required(),
197
+ moduleType: joi.string().required(),
198
+ filterByAuditType: joi.array().optional(),
199
+ sortColumnName: joi.string().optional(),
200
+ sortBy: joi.number().optional(),
201
+ isExport: joi.boolean().optional(),
202
+ },
203
+ );
204
+
205
+ export const pendingSummaryTableValid = {
206
+ body: pendingSummaryTableSchema,
207
+ };
208
+
209
+ export const overAllAuditSummarySchema = joi.object(
210
+ {
211
+ fromDate: joi.string().required(),
212
+ toDate: joi.string().required(),
213
+ clientId: joi.array().optional(),
214
+ moduleType: joi.string().required(),
215
+ },
216
+ );
217
+
218
+ export const overAllAuditSummaryValid = {
219
+ body: overAllAuditSummarySchema,
220
+ };
221
+
222
+ export const summarySplitSchema = joi.object(
223
+ {
224
+ fromDate: joi.string().required(),
225
+ toDate: joi.string().required(),
226
+ clientId: joi.array().optional(),
227
+ moduleType: joi.string().optional(),
228
+ },
229
+ );
230
+
231
+ export const summarySplitValid = {
232
+ body: summarySplitSchema,
233
+ };
234
+
235
+ export const overviewTableSchema = joi.object(
236
+ {
237
+ fromDate: joi.string().required(),
238
+ toDate: joi.string().required(),
239
+ clientId: joi.array().optional(),
240
+ limit: joi.number().optional(),
241
+ offset: joi.number().optional(),
242
+ searchValue: joi.string().optional().allow( '' ),
243
+ filterByStatus: joi.array().optional(),
244
+ moduleType: joi.string().optional(),
245
+ filterByAuditType: joi.array().optional(),
246
+ sortColumnName: joi.string().optional(),
247
+ sortBy: joi.number().optional(),
248
+ isExport: joi.boolean().optional(),
249
+ },
250
+ );
251
+
252
+ export const overviewTableValid= {
253
+ body: overviewTableSchema,
254
+ };
@@ -1,17 +1,36 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
- import { getDetectionFileValid, getFileValid } from '../dtos/traxAudit.dtos.js';
3
+ import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid } from '../dtos/traxAudit.dtos.js';
4
4
  import { isExistsQueue } from '../validation/audit.validation.js';
5
- import { getAuditFile, getDetectionAuditFile } from '../controllers/traxAudit.controllers.js';
5
+ import { clientMetrics, getAuditFile, getDetectionAuditFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
6
+ import { validateBinaryAudit } from '../validation/traxAuditValidation.js';
6
7
 
7
8
  export const traxAuditRouter = Router();
8
9
 
9
10
  // Audit Mapping
10
- traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
11
- traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
11
+
12
+ traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
12
13
  // traxAuditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
13
14
  // traxAuditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
14
- // traxAuditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
15
- // traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
15
+ // traxAuditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserEmpDetection, save ); use this validateuserEMpDetection
16
+ traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
17
+
18
+
19
+ // Y/n
20
+ traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
21
+ traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate( saveValid ), validateBinaryAudit, saveBinary );
22
+
23
+ // metrcis
24
+ traxAuditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
25
+ traxAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
26
+ traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
27
+ traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
28
+ traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
29
+ traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
30
+
31
+ // summary
32
+
33
+ traxAuditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
34
+ traxAuditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
16
35
 
17
36
  export default traxAuditRouter;
@@ -5,6 +5,14 @@ export function createBinaryAudit( record ) {
5
5
  return binaryAuditModel.create( record );
6
6
  }
7
7
 
8
- export function aggregateBinaryAuditModel( query ) {
8
+ export function aggregateBinaryAudit( query ) {
9
9
  return binaryAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
10
10
  }
11
+
12
+ export function findOneBinaryAudit( query ) {
13
+ return binaryAuditModel.findOne( query );
14
+ }
15
+
16
+ export function updateOneBinaryAuditModel( query, record ) {
17
+ return binaryAuditModel.updateOne( query, { $set: record } );
18
+ }
@@ -0,0 +1,6 @@
1
+ import storeEmpDetectionModel from 'tango-api-schema/schema/storeEmpDetection.model.js';
2
+
3
+
4
+ export function aggregateStoreEmpDetection( query ) {
5
+ return storeEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
+ }
@@ -0,0 +1,10 @@
1
+
2
+ import traxAuditDataModel from 'tango-api-schema/schema/traxAuditData.model.js';
3
+
4
+ export function findOneTraxAuditData( query, fields, sort ) {
5
+ return traxAuditDataModel.findOne( query, fields ).sort( sort );
6
+ }
7
+
8
+ export function aggregateTraxAuditData( query ) {
9
+ return traxAuditDataModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
10
+ }
@@ -1,6 +1,14 @@
1
1
  import userEmpDetectionModel from 'tango-api-schema/schema/userEmpDetection.model.js';
2
2
 
3
3
 
4
- export function aggregateUserAudit( query ) {
4
+ export function aggregateUserEmpDetection( query ) {
5
5
  return userEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
6
  }
7
+
8
+ export function createUserEmpDetection( record ) {
9
+ return userEmpDetectionModel.create( record );
10
+ }
11
+
12
+ export function findOneUserEmpDetection( query, fields ) {
13
+ return userEmpDetectionModel.findOne( query, fields );
14
+ }
@@ -0,0 +1,56 @@
1
+ import { findOneBinaryAudit } from '../service/binaryAudit.service.js';
2
+ import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
3
+
4
+ export async function validateUserEmpDetection( req, res, next ) {
5
+ try {
6
+ const inputData = req.body;
7
+ const userAuditDetails = await findOneUserEmpDetection( {
8
+ _id: inputData.auditId,
9
+ } );
10
+ if ( !userAuditDetails ) {
11
+ return res.sendError( 'No Data Available' );
12
+ } else if ( userAuditDetails && userAuditDetails.auditStatus == 'skipped' ) {
13
+ return res.sendError( 'The Audit file Assigned to some one else', 203 );
14
+ }
15
+ req.userAudit = userAuditDetails;
16
+ next();
17
+ } catch ( error ) {
18
+ const err = error.message || 'Internal Server Error';
19
+ logger.error( {
20
+ error: error,
21
+ message: req.query,
22
+ function: 'validateUserEmpDetection',
23
+ } );
24
+ return res.sendError( err, 500 );
25
+ }
26
+ }
27
+
28
+ export async function validateBinaryAudit( req, res, next ) {
29
+ try {
30
+ const inputData = req.body;
31
+ const userAuditDetails = await findOneBinaryAudit( {
32
+ _id: inputData.auditId,
33
+ } );
34
+ if ( !userAuditDetails ) {
35
+ return res.sendError( 'No Data Available' );
36
+ } else if (
37
+ userAuditDetails &&
38
+ userAuditDetails.auditStatus == 'completed'
39
+ ) {
40
+ await updateOneBinaryAuditModel(
41
+ { _id: inputData.auditId },
42
+ { auditType: 'ReAudit' },
43
+ );
44
+ }
45
+ req.userAudit = userAuditDetails;
46
+ next();
47
+ } catch ( error ) {
48
+ const err = error.message || 'Internal Server Error';
49
+ logger.error( {
50
+ error: error,
51
+ message: req.query,
52
+ function: 'validateBinaryAudit',
53
+ } );
54
+ return res.sendError( err, 500 );
55
+ }
56
+ }