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

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 } from '../dtos/traxAudit.dtos.js';
3
3
 
4
4
  export const traxAuditDocs = {
5
5
 
@@ -43,4 +43,139 @@ 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
+ },
46
181
  };
@@ -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().required(),
83
77
  },
84
78
  );
85
79
 
@@ -103,3 +97,90 @@ 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
+ };
@@ -1,17 +1,29 @@
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 } 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, saveBinary, storeMetrics, 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 );
16
28
 
17
29
  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,39 @@
1
+ import { findOneBinaryAudit } from '../service/binaryAudit.service.js';
2
+ import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
3
+
4
+
5
+ export async function validateUserEmpDetection( req, res, next ) {
6
+ try {
7
+ const inputData = req.body;
8
+ const userAuditDetails =await findOneUserEmpDetection( { _id: inputData.auditId } );
9
+ if ( !userAuditDetails ) {
10
+ return res.sendError( 'No Data Available' );
11
+ } else if ( userAuditDetails && userAuditDetails.auditStatus == 'skipped' ) {
12
+ return res.sendError( 'The Audit file Assigned to some one else', 203 );
13
+ }
14
+ req.userAudit = userAuditDetails;
15
+ next();
16
+ } catch ( error ) {
17
+ const err = error.message || 'Internal Server Error';
18
+ logger.error( { error: error, message: req.query, function: 'validateUserEmpDetection' } );
19
+ return res.sendError( err, 500 );
20
+ }
21
+ }
22
+
23
+ export async function validateBinaryAudit( req, res, next ) {
24
+ try {
25
+ const inputData = req.body;
26
+ const userAuditDetails =await findOneBinaryAudit( { _id: inputData.auditId } );
27
+ if ( !userAuditDetails ) {
28
+ return res.sendError( 'No Data Available' );
29
+ } else if ( userAuditDetails && userAuditDetails.auditStatus == 'completed' ) {
30
+ return res.sendError( 'Forbidden to this action', 203 );
31
+ }
32
+ req.userAudit = userAuditDetails;
33
+ next();
34
+ } catch ( error ) {
35
+ const err = error.message || 'Internal Server Error';
36
+ logger.error( { error: error, message: req.query, function: 'validateBinaryAudit' } );
37
+ return res.sendError( err, 500 );
38
+ }
39
+ }