tango-app-api-audit 1.0.35 → 1.0.37
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/.eslintrc.cjs +1 -1
- package/README.md +28 -28
- package/package.json +40 -40
- package/src/controllers/zoneAudit.controller.js +567 -10
- package/src/docs/zoneAudit.docs.js +101 -95
- package/src/dtos/zoneAudit.dtos.js +48 -0
- package/src/routes/zone.routes.js +7 -3
package/.eslintrc.cjs
CHANGED
package/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# README #
|
|
2
|
-
|
|
3
|
-
This README would normally document whatever steps are necessary to get your application up and running.
|
|
4
|
-
|
|
5
|
-
### What is this repository for? ###
|
|
6
|
-
|
|
7
|
-
* Quick summary
|
|
8
|
-
* Version
|
|
9
|
-
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
|
10
|
-
|
|
11
|
-
### How do I get set up? ###
|
|
12
|
-
|
|
13
|
-
* Summary of set up
|
|
14
|
-
* Configuration
|
|
15
|
-
* Dependencies
|
|
16
|
-
* Database configuration
|
|
17
|
-
* How to run tests
|
|
18
|
-
* Deployment instructions
|
|
19
|
-
|
|
20
|
-
### Contribution guidelines ###
|
|
21
|
-
|
|
22
|
-
* Writing tests
|
|
23
|
-
* Code review
|
|
24
|
-
* Other guidelines
|
|
25
|
-
|
|
26
|
-
### Who do I talk to? ###
|
|
27
|
-
|
|
28
|
-
* Repo owner or admin
|
|
1
|
+
# README #
|
|
2
|
+
|
|
3
|
+
This README would normally document whatever steps are necessary to get your application up and running.
|
|
4
|
+
|
|
5
|
+
### What is this repository for? ###
|
|
6
|
+
|
|
7
|
+
* Quick summary
|
|
8
|
+
* Version
|
|
9
|
+
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
|
10
|
+
|
|
11
|
+
### How do I get set up? ###
|
|
12
|
+
|
|
13
|
+
* Summary of set up
|
|
14
|
+
* Configuration
|
|
15
|
+
* Dependencies
|
|
16
|
+
* Database configuration
|
|
17
|
+
* How to run tests
|
|
18
|
+
* Deployment instructions
|
|
19
|
+
|
|
20
|
+
### Contribution guidelines ###
|
|
21
|
+
|
|
22
|
+
* Writing tests
|
|
23
|
+
* Code review
|
|
24
|
+
* Other guidelines
|
|
25
|
+
|
|
26
|
+
### Who do I talk to? ###
|
|
27
|
+
|
|
28
|
+
* Repo owner or admin
|
|
29
29
|
* Other community or team contact
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "audit & audit metrics apis",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . &&
|
|
9
|
-
},
|
|
10
|
-
"engines": {
|
|
11
|
-
"node": ">=18.10.0"
|
|
12
|
-
},
|
|
13
|
-
"author": "praveenraj",
|
|
14
|
-
"license": "ISC",
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"adm-zip": "^0.5.15",
|
|
17
|
-
"aws-sdk": "^2.1643.0",
|
|
18
|
-
"dayjs": "^1.11.11",
|
|
19
|
-
"dotenv": "^16.4.5",
|
|
20
|
-
"express": "^4.19.2",
|
|
21
|
-
"handlebars": "^4.7.8",
|
|
22
|
-
"joi-to-swagger": "^6.2.0",
|
|
23
|
-
"lodash": "^4.17.21",
|
|
24
|
-
"mongodb": "^6.7.0",
|
|
25
|
-
"nodemon": "^3.1.3",
|
|
26
|
-
"swagger-ui-express": "^5.0.1",
|
|
27
|
-
"tango-api-schema": "^2.0.
|
|
28
|
-
"tango-app-api-middleware": "^3.1.28",
|
|
29
|
-
"winston": "^3.13.0",
|
|
30
|
-
"winston-daily-rotate-file": "^5.0.0"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"eslint": "^8.57.0",
|
|
34
|
-
"eslint-config-google": "^0.14.0",
|
|
35
|
-
"eslint-config-semistandard": "^17.0.0",
|
|
36
|
-
"eslint-config-standard": "^17.1.0",
|
|
37
|
-
"eslint-plugin-import": "^2.29.1",
|
|
38
|
-
"eslint-plugin-promise": "^6.2.0"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "tango-app-api-audit",
|
|
3
|
+
"version": "1.0.37",
|
|
4
|
+
"description": "audit & audit metrics apis",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node index.js\""
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.10.0"
|
|
12
|
+
},
|
|
13
|
+
"author": "praveenraj",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"adm-zip": "^0.5.15",
|
|
17
|
+
"aws-sdk": "^2.1643.0",
|
|
18
|
+
"dayjs": "^1.11.11",
|
|
19
|
+
"dotenv": "^16.4.5",
|
|
20
|
+
"express": "^4.19.2",
|
|
21
|
+
"handlebars": "^4.7.8",
|
|
22
|
+
"joi-to-swagger": "^6.2.0",
|
|
23
|
+
"lodash": "^4.17.21",
|
|
24
|
+
"mongodb": "^6.7.0",
|
|
25
|
+
"nodemon": "^3.1.3",
|
|
26
|
+
"swagger-ui-express": "^5.0.1",
|
|
27
|
+
"tango-api-schema": "^2.0.144",
|
|
28
|
+
"tango-app-api-middleware": "^3.1.28",
|
|
29
|
+
"winston": "^3.13.0",
|
|
30
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"eslint": "^8.57.0",
|
|
34
|
+
"eslint-config-google": "^0.14.0",
|
|
35
|
+
"eslint-config-semistandard": "^17.0.0",
|
|
36
|
+
"eslint-config-standard": "^17.1.0",
|
|
37
|
+
"eslint-plugin-import": "^2.29.1",
|
|
38
|
+
"eslint-plugin-promise": "^6.2.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { getUTC, insertOpenSearchData, listFileByPath, signedUrl, sqsReceive } from 'tango-app-api-middleware';
|
|
1
|
+
import { download, getJsonFileData, getUTC, insertOpenSearchData, listFileByPath, sendMessageToQueue, signedUrl, sqsReceive } from 'tango-app-api-middleware';
|
|
2
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
|
-
import { createStoreZoneAudit } from '../service/storeZoneAudit.service.js';
|
|
5
|
+
import { aggregateStoreZoneAudit, createStoreZoneAudit, findOneStoreZoneAudit, updateOneStoreZoneAudit } from '../service/storeZoneAudit.service.js';
|
|
6
6
|
import { findOneUser } from '../service/user.service.js';
|
|
7
7
|
import { findOneStore } from '../service/store.service.js';
|
|
8
8
|
import dayjs from 'dayjs';
|
|
9
|
+
import { aggregateUserAudit, findOneUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
|
|
10
|
+
import { aggregateAssignAudit } from '../service/assignAudit.service.js';
|
|
11
|
+
import { createAuditLog, findOneAuditLog } from '../service/auditLog.service.js';
|
|
12
|
+
import { mapCustomer, mapEmployee, mapJunk, splitB20000, splitE0, splitG20000 } from '../validation/audit.validation.js';
|
|
13
|
+
import { aggregateClient } from '../service/client.service.js';
|
|
14
|
+
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
15
|
+
import _ from 'lodash';
|
|
16
|
+
import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
9
17
|
|
|
10
18
|
export async function getZoneAuditFile( req, res ) {
|
|
11
19
|
try {
|
|
@@ -39,7 +47,6 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
39
47
|
},
|
|
40
48
|
];
|
|
41
49
|
const userDetails = await aggregateZoneUserAudit( userQuery );
|
|
42
|
-
console.log( userDetails, 'zoneAuditStatus==>' );
|
|
43
50
|
const zoneAuditStatus =
|
|
44
51
|
userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
45
52
|
|
|
@@ -64,13 +71,11 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
64
71
|
];
|
|
65
72
|
|
|
66
73
|
const userAssign = await aggregateAssignZoneAudit( query );
|
|
67
|
-
console.log( userAssign, 'userAssign' );
|
|
68
74
|
if ( userAssign.length > 0 ) {
|
|
69
75
|
logger.info( 'Hit in user assign', { inputData } );
|
|
70
76
|
} else {
|
|
71
77
|
logger.info( 'Hit in new file', { inputData } );
|
|
72
78
|
const consumer = await sqsReceive( inputData.queueName );
|
|
73
|
-
console.log( consumer, 'consumer' );
|
|
74
79
|
if ( !consumer ) {
|
|
75
80
|
logger.error( {
|
|
76
81
|
error: consumer,
|
|
@@ -194,13 +199,10 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
194
199
|
zoneName: msg.zone_id,
|
|
195
200
|
|
|
196
201
|
};
|
|
197
|
-
console.log( record );
|
|
198
|
-
console.log( storeRecord );
|
|
199
202
|
insertData = await createZoneUserAudit( record );
|
|
200
203
|
await createStoreZoneAudit( storeRecord );
|
|
201
204
|
} else {
|
|
202
205
|
insertData = userDetails[0];
|
|
203
|
-
console.log( insertData );
|
|
204
206
|
}
|
|
205
207
|
} else {
|
|
206
208
|
logger.error( {
|
|
@@ -316,7 +318,7 @@ export async function saveDraft( req, res ) {
|
|
|
316
318
|
const logData = {
|
|
317
319
|
userId: req.user._id,
|
|
318
320
|
userName: req.user.userName,
|
|
319
|
-
logType: '
|
|
321
|
+
logType: 'zoneAudit',
|
|
320
322
|
logSubType: 'auditDraft',
|
|
321
323
|
logData: {
|
|
322
324
|
auditType: inputData.auditType,
|
|
@@ -331,7 +333,7 @@ export async function saveDraft( req, res ) {
|
|
|
331
333
|
}
|
|
332
334
|
await createAuditLog( inputData );
|
|
333
335
|
await updateOneUserAudit( userQuery, userRecord );
|
|
334
|
-
await
|
|
336
|
+
await updateOneStoreZoneAudit( storeQuery, storeRecord );
|
|
335
337
|
return res.sendSuccess( {
|
|
336
338
|
result: 'The file has been drafted successfully',
|
|
337
339
|
} );
|
|
@@ -341,3 +343,558 @@ export async function saveDraft( req, res ) {
|
|
|
341
343
|
return res.sendError( err, 500 );
|
|
342
344
|
}
|
|
343
345
|
}
|
|
346
|
+
|
|
347
|
+
export async function getDraftedData( req, res ) {
|
|
348
|
+
try {
|
|
349
|
+
const inputData = req.query;
|
|
350
|
+
const userId = inputData.userId || req.user._id;
|
|
351
|
+
const query = {
|
|
352
|
+
fileDate: inputData.fileDate,
|
|
353
|
+
storeId: inputData.storeId,
|
|
354
|
+
zoneName: inputData.zoneName,
|
|
355
|
+
moduleType: 'zone',
|
|
356
|
+
userId: userId,
|
|
357
|
+
};
|
|
358
|
+
const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
359
|
+
|
|
360
|
+
if ( !result ) {
|
|
361
|
+
return res.sendError( 'No Data Found', 204 );
|
|
362
|
+
}
|
|
363
|
+
return res.sendSuccess( { result: result } );
|
|
364
|
+
} catch ( error ) {
|
|
365
|
+
const err = error.message || 'Internal Server Error';
|
|
366
|
+
logger.error( {
|
|
367
|
+
error: error,
|
|
368
|
+
message: req.query,
|
|
369
|
+
function: 'getDraftedData',
|
|
370
|
+
} );
|
|
371
|
+
return res.sendError( err, 500 );
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export async function save( req, res ) {
|
|
376
|
+
try {
|
|
377
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
378
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
379
|
+
|
|
380
|
+
const inputData = req.body;
|
|
381
|
+
const params = {
|
|
382
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
if ( inputData.auditType === 'ReAudit' ) {
|
|
386
|
+
params.Bucket = bucket.auditUploadBucket;
|
|
387
|
+
} else {
|
|
388
|
+
params.Bucket = bucket.masterJson;
|
|
389
|
+
}
|
|
390
|
+
const fileData = await getJsonFileData( params );
|
|
391
|
+
|
|
392
|
+
if ( fileData?.statusCode ) {
|
|
393
|
+
logger.error( {
|
|
394
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
395
|
+
type: 'UPLOAD_ERROR',
|
|
396
|
+
} );
|
|
397
|
+
return res.sendError( fileData, 500 );
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const masterJsonData = JSON.parse( fileData.toString( 'utf-8' ) );
|
|
401
|
+
|
|
402
|
+
const [ G20000, B20000, E0 ] = await Promise.all( [
|
|
403
|
+
splitG20000( masterJsonData.person_data ),
|
|
404
|
+
splitB20000( masterJsonData.person_data ),
|
|
405
|
+
splitE0( masterJsonData.person_data ),
|
|
406
|
+
] );
|
|
407
|
+
|
|
408
|
+
const [ mappingData ] = await Promise.all( [
|
|
409
|
+
mapEmployee( B20000, inputData.employee ),
|
|
410
|
+
mapJunk( B20000, inputData.junk ),
|
|
411
|
+
mapCustomer( B20000, inputData.customer ),
|
|
412
|
+
] );
|
|
413
|
+
|
|
414
|
+
const tempData = _.sortBy( [ ...mappingData, ...G20000, ...E0 ], 'index' );
|
|
415
|
+
|
|
416
|
+
const tempObject = { person_data: tempData };
|
|
417
|
+
|
|
418
|
+
const uploadDataParams = {
|
|
419
|
+
Bucket: bucket.auditUploadBucket,
|
|
420
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/`,
|
|
421
|
+
ContentType: 'application/json',
|
|
422
|
+
fileName: `${bucket.masterJsonFile}`,
|
|
423
|
+
body: JSON.stringify( tempObject ),
|
|
424
|
+
};
|
|
425
|
+
const mappingUpload = await fileUpload( uploadDataParams );
|
|
426
|
+
|
|
427
|
+
if ( mappingUpload?.statusCode ) {
|
|
428
|
+
logger.error( {
|
|
429
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
430
|
+
type: 'UPLOAD_ERROR',
|
|
431
|
+
} );
|
|
432
|
+
return res.sendError( mappingUpload, 500 );
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
let getUserAuditData = await findOneUserAudit( {
|
|
436
|
+
_id: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
437
|
+
} );
|
|
438
|
+
const isoDate = getUserAuditData.startTime;
|
|
439
|
+
const currentTime = dayjs();
|
|
440
|
+
const isoDateTime = dayjs( isoDate );
|
|
441
|
+
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
442
|
+
|
|
443
|
+
await updateOneUserAudit(
|
|
444
|
+
{ _id: new mongoose.Types.ObjectId( inputData.auditId ) },
|
|
445
|
+
{
|
|
446
|
+
auditStatus: 'completed',
|
|
447
|
+
endTime: Date.now(),
|
|
448
|
+
isDraft: false,
|
|
449
|
+
afterCount: inputData.customerCount,
|
|
450
|
+
timeSpent: timeDifferenceInMinutes,
|
|
451
|
+
},
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
/** *
|
|
455
|
+
*
|
|
456
|
+
* logs need to be added
|
|
457
|
+
*
|
|
458
|
+
*
|
|
459
|
+
*/
|
|
460
|
+
|
|
461
|
+
let storeConfig = await findOneStore(
|
|
462
|
+
{
|
|
463
|
+
storeId: getUserAuditData.storeId,
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
auditConfigs: 1,
|
|
467
|
+
clientId: 1,
|
|
468
|
+
},
|
|
469
|
+
);
|
|
470
|
+
let storeAuditData = await findOneStoreZoneAudit( {
|
|
471
|
+
storeId: inputData.storeId,
|
|
472
|
+
zoneName: inputData.zoneName,
|
|
473
|
+
fileDate: inputData.fileDate,
|
|
474
|
+
} );
|
|
475
|
+
|
|
476
|
+
let clientData = await findClient( { clientId: storeConfig.clientId } );
|
|
477
|
+
|
|
478
|
+
if ( (
|
|
479
|
+
( storeAuditData.beforeCount - inputData.customerCount ) /
|
|
480
|
+
storeAuditData.beforeCount <
|
|
481
|
+
storeConfig.auditConfigs.ratio
|
|
482
|
+
) && inputData.auditType == 'Audit' ) {
|
|
483
|
+
logger.info(
|
|
484
|
+
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
485
|
+
'Reaudit',
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
const sqsProduceQueue = {
|
|
489
|
+
QueueUrl: `${sqs.url}${clientData[0].auditConfigs.queueName}`,
|
|
490
|
+
MessageBody: JSON.stringify( {
|
|
491
|
+
store_id: inputData.storeId,
|
|
492
|
+
zone_id: inputData.zoneName,
|
|
493
|
+
audit_type: 'ReAudit',
|
|
494
|
+
curr_date: inputData.fileDate,
|
|
495
|
+
total_count: inputData.customerCount,
|
|
496
|
+
before_count: storeAuditData.beforeCount,
|
|
497
|
+
} ),
|
|
498
|
+
};
|
|
499
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
500
|
+
logger.info( { sqsQueue: sqsQueue } );
|
|
501
|
+
|
|
502
|
+
if ( sqsQueue.statusCode ) {
|
|
503
|
+
logger.error( {
|
|
504
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
505
|
+
type: 'UPLOAD_ERROR',
|
|
506
|
+
} );
|
|
507
|
+
return res.sendError( mappingUpload, 500 );
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
await updateOneStoreZoneAudit( { storeId: inputData.storeId, zoneName: inputData.zoneName },
|
|
511
|
+
{
|
|
512
|
+
status: 'not_assign',
|
|
513
|
+
afterCount: inputData.customerCount,
|
|
514
|
+
auditType: 'ReAudit',
|
|
515
|
+
timeSpent: timeDifferenceInMinutes,
|
|
516
|
+
} );
|
|
517
|
+
} else {
|
|
518
|
+
logger.info( 'Hit in Features', { data: ( _.omit( inputData, [ 'junk', 'employee', 'customer' ] ) ) } );
|
|
519
|
+
await updateOneStoreZoneAudit( { storeId: inputData.storeId, zoneName: inputData.zoneName },
|
|
520
|
+
{
|
|
521
|
+
status: 'completed',
|
|
522
|
+
afterCount: inputData.customerCount,
|
|
523
|
+
timeSpent: timeDifferenceInMinutes,
|
|
524
|
+
} );
|
|
525
|
+
|
|
526
|
+
const sqsProduceQueue = {
|
|
527
|
+
QueueUrl: `${sqs.url}${sqs.feature}`,
|
|
528
|
+
|
|
529
|
+
MessageBody: JSON.stringify( {
|
|
530
|
+
store_id: inputData.storeId,
|
|
531
|
+
zone_id: inputData.zoneName,
|
|
532
|
+
store_date: inputData.fileDate,
|
|
533
|
+
bucket_name: `${bucket.auditUploadBucket}`,
|
|
534
|
+
process_type: 'audit',
|
|
535
|
+
} ),
|
|
536
|
+
};
|
|
537
|
+
logger.info( { sqsProduceQueue: sqsProduceQueue } );
|
|
538
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
539
|
+
logger.info( { sqsQueue: sqsQueue } );
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return res.sendSuccess( { result: 'Updated Successfully' } );
|
|
543
|
+
} catch ( error ) {
|
|
544
|
+
const err = error.message || 'Internal Server Error';
|
|
545
|
+
logger.error( { error: error, message: req.body, function: 'save' } );
|
|
546
|
+
return res.sendError( err );
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export async function workSpace( req, res ) {
|
|
551
|
+
try {
|
|
552
|
+
const inputData = req.query;
|
|
553
|
+
const limit = inputData.limit || 10;
|
|
554
|
+
const offset = inputData.offset ?
|
|
555
|
+
( inputData.offset - 1 ) * inputData.limit : 0;
|
|
556
|
+
const dateRange = await getUTC( new Date(), new Date() );
|
|
557
|
+
|
|
558
|
+
const temp = [];
|
|
559
|
+
const clientQuery = [
|
|
560
|
+
{
|
|
561
|
+
$match: {
|
|
562
|
+
$and: [
|
|
563
|
+
{ status: { $in: [ 'active', 'hold' ] } },
|
|
564
|
+
{ 'auditConfigs.audit': { $eq: true } }, // NOTE: modified the code need to check for enable zone
|
|
565
|
+
],
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
$project: {
|
|
570
|
+
clientName: '$clientName',
|
|
571
|
+
clientId: '$clientId',
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
];
|
|
575
|
+
|
|
576
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
577
|
+
clientQuery.push( {
|
|
578
|
+
$match: {
|
|
579
|
+
$or: [
|
|
580
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
581
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
582
|
+
],
|
|
583
|
+
},
|
|
584
|
+
} );
|
|
585
|
+
}
|
|
586
|
+
const count = await aggregateClient( clientQuery );
|
|
587
|
+
logger.info( { count: count } );
|
|
588
|
+
if ( count?.length == 0 ) {
|
|
589
|
+
return res.sendError( 'No Data Found', 204 );
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if ( inputData.limit && !inputData.isExport ) {
|
|
593
|
+
clientQuery.push( { $skip: offset }, { $limit: limit } );
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const clientDetails = await aggregateClient( clientQuery );
|
|
597
|
+
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
598
|
+
const query = [
|
|
599
|
+
{
|
|
600
|
+
$match: {
|
|
601
|
+
$and: [
|
|
602
|
+
{
|
|
603
|
+
clientId: { $in: clientList },
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
moduleType: 'zone',
|
|
607
|
+
},
|
|
608
|
+
],
|
|
609
|
+
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
$group: {
|
|
614
|
+
_id: '$clientId',
|
|
615
|
+
clientId: { $last: '$clientId' },
|
|
616
|
+
totalFilesCount: { $last: '$totalFilesCount' },
|
|
617
|
+
clientName: { $last: '$clientName' },
|
|
618
|
+
queueName: { $last: '$queueName' },
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
$project: {
|
|
623
|
+
clientId: 1,
|
|
624
|
+
totalFilesCount: 1,
|
|
625
|
+
clientName: 1,
|
|
626
|
+
queueName: 1,
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
];
|
|
630
|
+
|
|
631
|
+
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
632
|
+
|
|
633
|
+
const completedFiles = [
|
|
634
|
+
{
|
|
635
|
+
$match: {
|
|
636
|
+
$and: [
|
|
637
|
+
{ clientId: { $in: clientList } },
|
|
638
|
+
{ fileDateISO: { $eq: new Date( fileDate ) } },
|
|
639
|
+
],
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
$project: {
|
|
644
|
+
clientId: 1,
|
|
645
|
+
completed: {
|
|
646
|
+
$cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ],
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
$group: {
|
|
652
|
+
_id: { clientId: '$clientId', storeId: '$storeId' },
|
|
653
|
+
clientId: { $first: '$clientId' },
|
|
654
|
+
completedCount: { $sum: '$completed' },
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
$group: {
|
|
659
|
+
_id: '$clientId',
|
|
660
|
+
clientId: { $first: '$clientId' },
|
|
661
|
+
completedCount: { $first: '$completedCount' },
|
|
662
|
+
},
|
|
663
|
+
},
|
|
664
|
+
];
|
|
665
|
+
|
|
666
|
+
const auditFiles = [
|
|
667
|
+
{
|
|
668
|
+
$match: {
|
|
669
|
+
$and: [
|
|
670
|
+
{ clientId: { $in: clientList } },
|
|
671
|
+
{ moduleType: { $eq: 'zone' } },
|
|
672
|
+
{ createdAt: { $gte: dateRange.start } },
|
|
673
|
+
{ createdAt: { $lte: dateRange.end } },
|
|
674
|
+
],
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
$project: {
|
|
679
|
+
clientId: 1,
|
|
680
|
+
pending: {
|
|
681
|
+
$cond: [
|
|
682
|
+
{ $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] } ] },
|
|
683
|
+
1,
|
|
684
|
+
0,
|
|
685
|
+
],
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
$group: {
|
|
691
|
+
_id: { clientId: '$clientId', storeId: '$storeId' },
|
|
692
|
+
clientId: { $first: '$clientId' },
|
|
693
|
+
pendingCount: { $sum: '$pending' },
|
|
694
|
+
totalCount: { $sum: 1 },
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
$group: {
|
|
699
|
+
_id: '$clientId',
|
|
700
|
+
clientId: { $first: '$clientId' },
|
|
701
|
+
pendingCount: { $first: { $ifNull: [ '$pendingCount', 0 ] } },
|
|
702
|
+
totalCount: { $first: '$totalCount' },
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
];
|
|
706
|
+
|
|
707
|
+
const draftedFiles = [
|
|
708
|
+
{
|
|
709
|
+
$match: {
|
|
710
|
+
$and: [
|
|
711
|
+
{ clientId: { $in: clientList } },
|
|
712
|
+
{ moduleType: { $eq: 'zone' } },
|
|
713
|
+
{ userId: { $eq: inputData.userId } },
|
|
714
|
+
{ createdAt: { $gte: dateRange.start } },
|
|
715
|
+
{ createdAt: { $lte: dateRange.end } },
|
|
716
|
+
],
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
$sort: {
|
|
721
|
+
updatedAt: -1,
|
|
722
|
+
},
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
$project: {
|
|
726
|
+
clientId: 1,
|
|
727
|
+
isDraft: 1,
|
|
728
|
+
draft: {
|
|
729
|
+
$cond: [ { $eq: [ '$auditStatus', 'drafted' ] }, 1, 0 ],
|
|
730
|
+
},
|
|
731
|
+
inprogress: {
|
|
732
|
+
$cond: [ { $eq: [ '$auditStatus', 'inprogress' ] }, 1, 0 ],
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
$group: {
|
|
738
|
+
_id: '$clientId',
|
|
739
|
+
clientId: { $first: '$clientId' },
|
|
740
|
+
isDrafted: { $first: '$isDraft' },
|
|
741
|
+
draftCount: { $sum: '$draft' },
|
|
742
|
+
inprogressCount: { $sum: '$inprogress' },
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
];
|
|
746
|
+
|
|
747
|
+
const userAsign = [
|
|
748
|
+
{
|
|
749
|
+
$match: {
|
|
750
|
+
$and: [
|
|
751
|
+
{ userId: { $eq: req.user._id } },
|
|
752
|
+
{ isCompleted: false },
|
|
753
|
+
{ clientId: { $in: clientList } },
|
|
754
|
+
{ moduleType: { $eq: 'zone' } } ],
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
$group: {
|
|
759
|
+
_id: '$clientId',
|
|
760
|
+
clientId: { $first: '$clientId' },
|
|
761
|
+
asignedCount: { $sum: 1 },
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
$project: {
|
|
766
|
+
_id: 0,
|
|
767
|
+
clientId: 1,
|
|
768
|
+
asignedCount: 1,
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
];
|
|
772
|
+
|
|
773
|
+
const clientAssign = [
|
|
774
|
+
{
|
|
775
|
+
$match: {
|
|
776
|
+
$and: [
|
|
777
|
+
{ isCompleted: false },
|
|
778
|
+
{ moduleType: { $eq: 'zone' } },
|
|
779
|
+
{ clientId: { $in: clientList } },
|
|
780
|
+
],
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
$group: {
|
|
785
|
+
_id: '$clientId',
|
|
786
|
+
clientId: { $first: '$clientId' },
|
|
787
|
+
ClientAsignedCount: { $sum: 1 },
|
|
788
|
+
},
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
$project: {
|
|
792
|
+
_id: 0,
|
|
793
|
+
clientId: 1,
|
|
794
|
+
ClientAsignedCount: { $ifNull: [ '$ClientAsignedCount', 0 ] },
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
];
|
|
798
|
+
|
|
799
|
+
const auditDetails = await aggregateAuditClientData( query );
|
|
800
|
+
const auditCount = await aggregateUserAudit( auditFiles );
|
|
801
|
+
const draftedCount = await aggregateUserAudit( draftedFiles );
|
|
802
|
+
const CompletedCount = await aggregateStoreZoneAudit( completedFiles );
|
|
803
|
+
|
|
804
|
+
const clientAssignresult = await aggregateAssignAudit( clientAssign );
|
|
805
|
+
const userAsignCount = await aggregateAssignAudit( userAsign );
|
|
806
|
+
const mergeAll = _.merge(
|
|
807
|
+
_.keyBy( clientDetails, 'clientId' ),
|
|
808
|
+
_.keyBy( auditCount, 'clientId' ),
|
|
809
|
+
_.keyBy( draftedCount, 'clientId' ),
|
|
810
|
+
_.keyBy( clientAssignresult, 'clientId' ),
|
|
811
|
+
);
|
|
812
|
+
const finalResult = _.values( mergeAll );
|
|
813
|
+
const merge = _.values(
|
|
814
|
+
_.merge(
|
|
815
|
+
_.keyBy( finalResult, 'clientId' ),
|
|
816
|
+
_.keyBy( auditDetails, 'clientId' ),
|
|
817
|
+
_.keyBy( userAsignCount, 'clientId' ),
|
|
818
|
+
_.keyBy( CompletedCount, 'clientId' ),
|
|
819
|
+
),
|
|
820
|
+
);
|
|
821
|
+
logger.info( { merge: merge } );
|
|
822
|
+
let totalStores = 0;
|
|
823
|
+
for ( let i = 0; i < merge.length; i++ ) {
|
|
824
|
+
totalStores = totalStores + merge[i].totalFilesCount;
|
|
825
|
+
|
|
826
|
+
const pending = await listQueue( merge[i].queueName );
|
|
827
|
+
|
|
828
|
+
if ( !pending.statusCode ) {
|
|
829
|
+
temp.push( {
|
|
830
|
+
clientId: merge[i].clientId,
|
|
831
|
+
clientName: merge[i].clientName,
|
|
832
|
+
completedCount: merge[i].completedCount ?
|
|
833
|
+
Number( merge[i].completedCount ) :
|
|
834
|
+
0,
|
|
835
|
+
pendingByQueue: Number( pending ),
|
|
836
|
+
pendingByUser:
|
|
837
|
+
merge[i].pendingCount >= 0 ?
|
|
838
|
+
Number( merge[i].pendingCount ) +
|
|
839
|
+
( merge[i].ClientAsignedCount ?
|
|
840
|
+
Number( merge[i].ClientAsignedCount ) :
|
|
841
|
+
0 ) :
|
|
842
|
+
0,
|
|
843
|
+
totalCount: merge[i].totalFilesCount,
|
|
844
|
+
queueName: merge[i].queueName,
|
|
845
|
+
isDraft: merge[i].isDrafted ? merge[i].isDrafted : false,
|
|
846
|
+
isEnable:
|
|
847
|
+
Number( pending ) > 0 ||
|
|
848
|
+
merge[i].isDrafted ||
|
|
849
|
+
( merge[i].asignedCount && merge[i].asignedCount > 0 ) ||
|
|
850
|
+
( merge[i].inprogressCount && merge[i].inprogressCount > 0 ) ?
|
|
851
|
+
true :
|
|
852
|
+
false,
|
|
853
|
+
completedRatio: merge[i].totalFilesCount ?
|
|
854
|
+
merge[i].completedCount ?
|
|
855
|
+
Math.round(
|
|
856
|
+
( Number( merge[i].completedCount ) /
|
|
857
|
+
Number( merge[i].totalFilesCount ) ) *
|
|
858
|
+
100,
|
|
859
|
+
) :
|
|
860
|
+
0 :
|
|
861
|
+
0,
|
|
862
|
+
isAssigned:
|
|
863
|
+
merge[i].asignedCount && merge[i].asignedCount > 0 ? true : false,
|
|
864
|
+
Assignedcount:
|
|
865
|
+
merge[i].asignedCount && merge[i].asignedCount > 0 ?
|
|
866
|
+
merge[i].asignedCount :
|
|
867
|
+
0,
|
|
868
|
+
} );
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
if ( inputData.isExport ) {
|
|
873
|
+
const exportdata = [];
|
|
874
|
+
temp.forEach( ( element ) => {
|
|
875
|
+
exportdata.push( {
|
|
876
|
+
'Client Name': element.clientName,
|
|
877
|
+
'Client Id': element.clientId,
|
|
878
|
+
'Completed Percentage': element.completedRatio + ' %',
|
|
879
|
+
'Pending Queue': element.pendingByQueue,
|
|
880
|
+
'Pending User': element.pendingByUser,
|
|
881
|
+
'Completed': element.completedCount,
|
|
882
|
+
'Draft': element.isDraft ? 1 : 0,
|
|
883
|
+
'Assigned': element.Assignedcount,
|
|
884
|
+
} );
|
|
885
|
+
} );
|
|
886
|
+
await download( exportdata, res );
|
|
887
|
+
return;
|
|
888
|
+
} else {
|
|
889
|
+
return res.sendSuccess( {
|
|
890
|
+
result: temp,
|
|
891
|
+
count: count.length,
|
|
892
|
+
totalStores: totalStores,
|
|
893
|
+
} );
|
|
894
|
+
}
|
|
895
|
+
} catch ( error ) {
|
|
896
|
+
const err = error.message || 'Internal Server Error';
|
|
897
|
+
logger.info( { error: error, message: req.query, function: 'workSpace' } );
|
|
898
|
+
return res.sendError( err, 500 );
|
|
899
|
+
}
|
|
900
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema, saveDraftSchema } from '../dtos/zoneAudit.dtos.js';
|
|
2
|
+
import { getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema, workSpaceSchema } from '../dtos/zoneAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const zoneAuditDocs = {
|
|
5
|
-
'/v3/zone/get-file': {
|
|
5
|
+
'/v3/zone-audit/get-file': {
|
|
6
6
|
get: {
|
|
7
|
-
tags: [ 'Zone' ],
|
|
7
|
+
tags: [ 'Zone Audit' ],
|
|
8
8
|
description: 'Get a file via queue message',
|
|
9
9
|
operationId: 'get-file',
|
|
10
10
|
parameters: [
|
|
@@ -36,9 +36,9 @@ export const zoneAuditDocs = {
|
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
|
-
'/v3/audit/save-draft': {
|
|
39
|
+
'/v3/zone-audit/save-draft': {
|
|
40
40
|
post: {
|
|
41
|
-
tags: [ 'Zone' ],
|
|
41
|
+
tags: [ 'Zone Audit' ],
|
|
42
42
|
description: `saved zone audited file. which is save in the mongo db`,
|
|
43
43
|
operationId: 'save-draft',
|
|
44
44
|
parameters: {},
|
|
@@ -58,95 +58,101 @@ export const zoneAuditDocs = {
|
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
61
|
+
'/v3/zone-audit/get-drafted-data': {
|
|
62
|
+
get: {
|
|
63
|
+
tags: [ 'Zone Audit' ],
|
|
64
|
+
description: 'Get a saved file via DB',
|
|
65
|
+
operationId: 'get-drafted-data',
|
|
66
|
+
parameters: [
|
|
67
|
+
{
|
|
68
|
+
in: 'query',
|
|
69
|
+
name: 'fileDate',
|
|
70
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
71
|
+
require: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
in: 'query',
|
|
75
|
+
name: 'storeId',
|
|
76
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
77
|
+
require: true,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
in: 'query',
|
|
81
|
+
name: 'zoneName',
|
|
82
|
+
scema: j2s( getDraftedDataSchema ).swagger,
|
|
83
|
+
require: true,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
responses: {
|
|
87
|
+
200: { description: 'Successful' },
|
|
88
|
+
401: { description: 'Unauthorized User' },
|
|
89
|
+
422: { description: 'Field Error' },
|
|
90
|
+
500: { description: 'Server Error' },
|
|
91
|
+
204: { description: 'Not Found' },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
'/v3/zone-audit/save': {
|
|
96
|
+
post: {
|
|
97
|
+
tags: [ 'Zone Audit' ],
|
|
98
|
+
description: `submit the audit file. which is store in the bucket in the json format`,
|
|
99
|
+
operationId: 'save',
|
|
100
|
+
parameters: {},
|
|
101
|
+
requestBody: {
|
|
102
|
+
content: {
|
|
103
|
+
'application/json': {
|
|
104
|
+
schema: j2s( saveSchema ).swagger,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
responses: {
|
|
109
|
+
200: { description: 'The Audited file has been submited successfully ' },
|
|
110
|
+
401: { description: 'Unauthorized User' },
|
|
111
|
+
422: { description: 'Field Error' },
|
|
112
|
+
500: { description: 'Server Error' },
|
|
113
|
+
204: { description: 'Not Found' },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
'/v3/zone-audit/work-space': {
|
|
118
|
+
get: {
|
|
119
|
+
tags: [ 'Zone Audit' ],
|
|
120
|
+
description: 'queue wise info of audit files ',
|
|
121
|
+
operationId: 'work-space',
|
|
122
|
+
parameters: [
|
|
123
|
+
{
|
|
124
|
+
in: 'query',
|
|
125
|
+
name: 'searchValue',
|
|
126
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
127
|
+
require: false,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
in: 'query',
|
|
131
|
+
name: 'offset',
|
|
132
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
133
|
+
require: false,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
in: 'query',
|
|
137
|
+
name: 'limit',
|
|
138
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
139
|
+
require: false,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
in: 'query',
|
|
143
|
+
name: 'isExport',
|
|
144
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
145
|
+
require: false,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
responses: {
|
|
149
|
+
200: { description: 'Successful' },
|
|
150
|
+
401: { description: 'Unauthorized User' },
|
|
151
|
+
422: { description: 'Field Error' },
|
|
152
|
+
500: { description: 'Server Error' },
|
|
153
|
+
204: { description: 'Not Found' },
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
151
157
|
|
|
152
158
|
};
|
|
@@ -38,3 +38,51 @@ export const saveDraftSchema = joi.object(
|
|
|
38
38
|
export const saveDraftValid = {
|
|
39
39
|
body: saveDraftSchema,
|
|
40
40
|
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export const saveSchema = joi.object(
|
|
44
|
+
{
|
|
45
|
+
auditId: joi.string().required(),
|
|
46
|
+
storeId: joi.string().required(),
|
|
47
|
+
zoneName: joi.string().required(),
|
|
48
|
+
fileDate: joi.string().required(),
|
|
49
|
+
auditType: joi.string().required(),
|
|
50
|
+
beforeCount: joi.number().required(),
|
|
51
|
+
junkCount: joi.number().required(),
|
|
52
|
+
junk: joi.array().required(),
|
|
53
|
+
employeeCount: joi.number().required(),
|
|
54
|
+
employee: joi.array().required(),
|
|
55
|
+
customerCount: joi.number().required(),
|
|
56
|
+
customer: joi.array().required(),
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export const saveValid = {
|
|
61
|
+
body: saveSchema,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getDraftedDataSchema = joi.object(
|
|
65
|
+
{
|
|
66
|
+
storeId: joi.string().required(),
|
|
67
|
+
zoneName: joi.string().required(),
|
|
68
|
+
fileDate: joi.string().required(),
|
|
69
|
+
userId: joi.string().optional(),
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export const getDraftedDataValid = {
|
|
74
|
+
query: getDraftedDataSchema,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const workSpaceSchema = joi.object(
|
|
78
|
+
{
|
|
79
|
+
searchValue: joi.string().optional().allow( '' ),
|
|
80
|
+
offset: joi.string().optional(),
|
|
81
|
+
limit: joi.number().optional(),
|
|
82
|
+
isExport: joi.boolean().optional(),
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
export const workSpaceValid = {
|
|
87
|
+
query: workSpaceSchema,
|
|
88
|
+
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { getFileValid, saveDraftValid } from '../dtos/zoneAudit.dtos.js';
|
|
3
|
-
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
2
|
+
import { getDraftedDataValid, getFileValid, saveDraftValid, saveValid, workSpaceValid } from '../dtos/zoneAudit.dtos.js';
|
|
3
|
+
import { isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
4
4
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
5
|
-
import { getZoneAuditFile, saveDraft } from '../controllers/zoneAudit.controller.js';
|
|
5
|
+
import { getDraftedData, getZoneAuditFile, save, saveDraft, workSpace } 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
11
|
zoneAuditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
|
|
12
|
+
zoneAuditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
|
|
13
|
+
zoneAuditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
|
|
14
|
+
zoneAuditRouter.get( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
|
|
15
|
+
|