tango-app-api-audit 1.0.33 → 1.0.35
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,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . &&
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && app index.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -1211,7 +1211,7 @@ export async function reTrigger( req, res ) {
|
|
|
1211
1211
|
}
|
|
1212
1212
|
|
|
1213
1213
|
const storeRecord ={
|
|
1214
|
-
status:
|
|
1214
|
+
status: req.audit.status !== 'completed' ? 'skipped': 'not_assign',
|
|
1215
1215
|
};
|
|
1216
1216
|
|
|
1217
1217
|
await updateOneStoreAudit( query, storeRecord );
|
|
@@ -1266,7 +1266,7 @@ export async function reTrigger( req, res ) {
|
|
|
1266
1266
|
}
|
|
1267
1267
|
|
|
1268
1268
|
const storeRecord ={
|
|
1269
|
-
status:
|
|
1269
|
+
status: req.audit.status !== 'completed' ? 'skipped': 'assigned',
|
|
1270
1270
|
};
|
|
1271
1271
|
|
|
1272
1272
|
await updateOneStoreAudit( query, storeRecord );
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { getUTC, insertOpenSearchData, listFileByPath, signedUrl, sqsReceive } from 'tango-app-api-middleware';
|
|
2
|
-
import { aggregateZoneUserAudit, createZoneUserAudit } from '../service/zoneUserAudit.service.js';
|
|
2
|
+
import { aggregateZoneUserAudit, createZoneUserAudit, findOneZoneUserAudit } from '../service/zoneUserAudit.service.js';
|
|
3
3
|
import { logger } from 'tango-app-api-middleware';
|
|
4
4
|
import { aggregateAssignZoneAudit } from '../service/assignZoneAudit.service.js';
|
|
5
5
|
import { createStoreZoneAudit } from '../service/storeZoneAudit.service.js';
|
|
6
6
|
import { findOneUser } from '../service/user.service.js';
|
|
7
7
|
import { findOneStore } from '../service/store.service.js';
|
|
8
|
+
import dayjs from 'dayjs';
|
|
8
9
|
|
|
9
10
|
export async function getZoneAuditFile( req, res ) {
|
|
10
11
|
try {
|
|
11
12
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
13
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
12
14
|
const inputData = req.query;
|
|
13
15
|
const data = await getUTC( new Date(), new Date() );
|
|
14
16
|
const start = data.start;
|
|
@@ -43,7 +45,6 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
43
45
|
|
|
44
46
|
switch ( zoneAuditStatus ) {
|
|
45
47
|
case null:
|
|
46
|
-
|
|
47
48
|
const query = [
|
|
48
49
|
{
|
|
49
50
|
$match: {
|
|
@@ -82,6 +83,22 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
82
83
|
}
|
|
83
84
|
break;
|
|
84
85
|
|
|
86
|
+
// case 'drafted':
|
|
87
|
+
// logger.info( 'userDetails drafted', { inputData } );
|
|
88
|
+
|
|
89
|
+
// const log = await findOneAuditLog(
|
|
90
|
+
// {
|
|
91
|
+
// userId: userDetails[0].userId,
|
|
92
|
+
// fileDate: userDetails[0].fileDate,
|
|
93
|
+
// storeId: userDetails[0].storeId,
|
|
94
|
+
// totalCount: userDetails[0].beforeCount,
|
|
95
|
+
|
|
96
|
+
// },
|
|
97
|
+
// {},
|
|
98
|
+
// { createdAt: -1 },
|
|
99
|
+
// );
|
|
100
|
+
|
|
101
|
+
|
|
85
102
|
default:
|
|
86
103
|
msg = {
|
|
87
104
|
store_id: userDetails[0].storeId,
|
|
@@ -253,3 +270,74 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
253
270
|
return res.sendError( error, 500 );
|
|
254
271
|
}
|
|
255
272
|
}
|
|
273
|
+
|
|
274
|
+
export async function saveDraft( req, res ) {
|
|
275
|
+
try {
|
|
276
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
277
|
+
const inputData = req.body;
|
|
278
|
+
inputData.userId = req.user._id;
|
|
279
|
+
const getUserAuditData = await findOneZoneUserAudit( { _id: inputData.auditId } );
|
|
280
|
+
if ( !getUserAuditData ) {
|
|
281
|
+
return res.sendError( 'No Data Found', 204 );
|
|
282
|
+
}
|
|
283
|
+
if ( getUserAuditData.auditStatus == 'skipped' ) {
|
|
284
|
+
return res.sendError( 'File Assigned to Someone else', 203 );
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const userQuery = {
|
|
288
|
+
_id: inputData.auditId,
|
|
289
|
+
};
|
|
290
|
+
let userRecord = {
|
|
291
|
+
isDraft: true,
|
|
292
|
+
auditStatus: 'drafted',
|
|
293
|
+
};
|
|
294
|
+
const storeQuery = {
|
|
295
|
+
storeId: inputData.storeId,
|
|
296
|
+
fileDate: inputData.fileDate,
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
let storeRecord = {
|
|
300
|
+
status: 'drafted',
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
if ( getUserAuditData?.startTime ) {
|
|
304
|
+
const isoDate = getUserAuditData.startTime;
|
|
305
|
+
const currentTime = dayjs();
|
|
306
|
+
const isoDateTime = dayjs( isoDate );
|
|
307
|
+
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
308
|
+
|
|
309
|
+
userRecord.timeSpent = timeDifferenceInMinutes;
|
|
310
|
+
|
|
311
|
+
storeRecord.timeSpent = timeDifferenceInMinutes;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if ( inputData.userCommands ) {
|
|
315
|
+
userRecord.userCommands = inputData.userCommands;
|
|
316
|
+
const logData = {
|
|
317
|
+
userId: req.user._id,
|
|
318
|
+
userName: req.user.userName,
|
|
319
|
+
logType: 'audit',
|
|
320
|
+
logSubType: 'auditDraft',
|
|
321
|
+
logData: {
|
|
322
|
+
auditType: inputData.auditType,
|
|
323
|
+
storeId: inputData.storeId,
|
|
324
|
+
clientName: inputData.queueName,
|
|
325
|
+
beforeCount: inputData.totalCount,
|
|
326
|
+
afterCount: inputData.customerCount,
|
|
327
|
+
auditId: inputData.auditId,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
331
|
+
}
|
|
332
|
+
await createAuditLog( inputData );
|
|
333
|
+
await updateOneUserAudit( userQuery, userRecord );
|
|
334
|
+
await updateOneStoreAudit( storeQuery, storeRecord );
|
|
335
|
+
return res.sendSuccess( {
|
|
336
|
+
result: 'The file has been drafted successfully',
|
|
337
|
+
} );
|
|
338
|
+
} catch ( error ) {
|
|
339
|
+
const err = error.message || 'Internal Server Error';
|
|
340
|
+
logger.error( { error: error, message: req.body, function: 'saveDraft' } );
|
|
341
|
+
return res.sendError( err, 500 );
|
|
342
|
+
}
|
|
343
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema } from '../dtos/zoneAudit.dtos.js';
|
|
2
|
+
import { getFileSchema, saveDraftSchema } from '../dtos/zoneAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const zoneAuditDocs = {
|
|
5
5
|
'/v3/zone/get-file': {
|
|
@@ -36,28 +36,28 @@ export const zoneAuditDocs = {
|
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
'/v3/audit/save-draft': {
|
|
40
|
+
post: {
|
|
41
|
+
tags: [ 'Zone' ],
|
|
42
|
+
description: `saved zone audited file. which is save in the mongo db`,
|
|
43
|
+
operationId: 'save-draft',
|
|
44
|
+
parameters: {},
|
|
45
|
+
requestBody: {
|
|
46
|
+
content: {
|
|
47
|
+
'application/json': {
|
|
48
|
+
schema: j2s( saveDraftSchema ).swagger,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
responses: {
|
|
53
|
+
200: { description: 'Successful' },
|
|
54
|
+
401: { description: 'Unauthorized User' },
|
|
55
|
+
422: { description: 'Field Error' },
|
|
56
|
+
500: { description: 'Server Error' },
|
|
57
|
+
204: { description: 'Not Found' },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
61
|
// '/v3/audit/get-drafted-data': {
|
|
62
62
|
// get: {
|
|
63
63
|
// tags: [ 'Audit' ],
|
|
@@ -13,3 +13,28 @@ export const getFileSchema = joi.object(
|
|
|
13
13
|
export const getFileValid = {
|
|
14
14
|
query: getFileSchema,
|
|
15
15
|
};
|
|
16
|
+
|
|
17
|
+
export const saveDraftSchema = joi.object(
|
|
18
|
+
{
|
|
19
|
+
userCommands: joi.string().optional().allow( '' ),
|
|
20
|
+
storeId: joi.string().required(),
|
|
21
|
+
auditId: joi.string().required(),
|
|
22
|
+
zoneName: joi.string().required(),
|
|
23
|
+
auditType: joi.string().required(),
|
|
24
|
+
fileDate: joi.string().required(),
|
|
25
|
+
queueName: joi.string().required(),
|
|
26
|
+
totalCount: joi.number().required(),
|
|
27
|
+
junkCount: joi.number().optional(),
|
|
28
|
+
junk: joi.array().optional(),
|
|
29
|
+
employeeCount: joi.number().optional(),
|
|
30
|
+
employee: joi.array().optional(),
|
|
31
|
+
customerCount: joi.number().optional(),
|
|
32
|
+
customer: joi.array().optional(),
|
|
33
|
+
retagCount: joi.number().optional(),
|
|
34
|
+
retagImage: joi.array().optional(),
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const saveDraftValid = {
|
|
39
|
+
body: saveDraftSchema,
|
|
40
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { getFileValid } from '../dtos/zoneAudit.dtos.js';
|
|
2
|
+
import { getFileValid, saveDraftValid } from '../dtos/zoneAudit.dtos.js';
|
|
3
3
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
4
4
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
5
|
-
import { getZoneAuditFile } from '../controllers/zoneAudit.controller.js';
|
|
5
|
+
import { getZoneAuditFile, saveDraft } from '../controllers/zoneAudit.controller.js';
|
|
6
6
|
|
|
7
7
|
export const zoneAuditRouter=Router();
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
zoneAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getZoneAuditFile );
|
|
11
|
+
zoneAuditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
|