tango-app-api-audit 3.3.0-alpha.12 → 3.3.0-alpha.14
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 +3 -3
- package/src/controllers/audit.controllers.js +20 -15
- package/src/docs/audit.docs.js +7 -44
- package/src/dtos/audit.dtos.js +3 -1
- package/src/routes/audit.routes.js +1 -1
- package/app.js +0 -38
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "3.3.0-alpha.
|
|
3
|
+
"version": "3.3.0-alpha.14",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node index.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -738,21 +738,24 @@ export const mapFunction = async ( chunk, filter ) => {
|
|
|
738
738
|
|
|
739
739
|
export async function workSpace( req, res ) {
|
|
740
740
|
try {
|
|
741
|
-
const inputData = req.
|
|
741
|
+
const inputData = req.body;
|
|
742
742
|
const limit = inputData.limit || 10;
|
|
743
743
|
const offset = inputData.offset ?
|
|
744
744
|
( inputData.offset - 1 ) * limit :
|
|
745
745
|
0;
|
|
746
746
|
const dateRange = await getUTC( new Date(), new Date() );
|
|
747
|
-
|
|
747
|
+
const filter =[
|
|
748
|
+
{ status: { $in: [ 'active', 'hold' ] } },
|
|
749
|
+
{ 'auditConfigs.audit': { $eq: true } },
|
|
750
|
+
];
|
|
751
|
+
if ( inputData?.clientId?.length > 0 ) {
|
|
752
|
+
filter.push( { clientId: { $in: inputData.clientId } } );
|
|
753
|
+
}
|
|
748
754
|
const temp = [];
|
|
749
755
|
const clientQuery = [
|
|
750
756
|
{
|
|
751
757
|
$match: {
|
|
752
|
-
$and:
|
|
753
|
-
{ status: { $in: [ 'active', 'hold' ] } },
|
|
754
|
-
{ 'auditConfigs.audit': { $eq: true } },
|
|
755
|
-
],
|
|
758
|
+
$and: filter,
|
|
756
759
|
},
|
|
757
760
|
},
|
|
758
761
|
{
|
|
@@ -777,7 +780,7 @@ export async function workSpace( req, res ) {
|
|
|
777
780
|
if ( inputData.sortColumnName ) {
|
|
778
781
|
const sortBy = inputData.sortBy || -1;
|
|
779
782
|
const sortColumn = inputData.sortColumnName;
|
|
780
|
-
|
|
783
|
+
clientQuery.push( {
|
|
781
784
|
$sort: { [sortColumn]: sortBy },
|
|
782
785
|
},
|
|
783
786
|
);
|
|
@@ -1475,7 +1478,9 @@ export async function userAuditHistory( req, res ) {
|
|
|
1475
1478
|
auditStatus: { $in: inputData.filterByStatus },
|
|
1476
1479
|
} );
|
|
1477
1480
|
}
|
|
1478
|
-
|
|
1481
|
+
if ( inputData?.clientId?.length > 0 ) {
|
|
1482
|
+
filter.push( { clientId: { $in: inputData.clientId } } );
|
|
1483
|
+
}
|
|
1479
1484
|
const query = [
|
|
1480
1485
|
{
|
|
1481
1486
|
$match: {
|
|
@@ -1639,18 +1644,18 @@ export async function userAuditHistory( req, res ) {
|
|
|
1639
1644
|
chunk.forEach( ( element ) => {
|
|
1640
1645
|
exportData.push( {
|
|
1641
1646
|
|
|
1642
|
-
'
|
|
1643
|
-
'
|
|
1647
|
+
'Brand ID': element.clientId,
|
|
1648
|
+
'Brand Name': element.clientName,
|
|
1644
1649
|
'Store ID': element.storeId,
|
|
1645
1650
|
'Store Name': element.storeName,
|
|
1646
1651
|
'Zone Name': element.zoneName,
|
|
1647
1652
|
'Audit Type': element.auditType,
|
|
1648
1653
|
'Module Type': element.moduleType,
|
|
1649
1654
|
'Before Count': element.beforeCount,
|
|
1650
|
-
'After Count': element.afterCount,
|
|
1651
|
-
'Accuracy': element.accuracy,
|
|
1655
|
+
'After Count': element.afterCount || '',
|
|
1656
|
+
'Accuracy': element.accuracy || '',
|
|
1652
1657
|
'Start Time': element.startTime,
|
|
1653
|
-
'End Time': element.endTime,
|
|
1658
|
+
'End Time': element.endTime || '',
|
|
1654
1659
|
'Time Spent': element.timeSpent,
|
|
1655
1660
|
'Audit Status': element.auditStatus,
|
|
1656
1661
|
'CreatedAt': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
|
|
@@ -1661,8 +1666,8 @@ export async function userAuditHistory( req, res ) {
|
|
|
1661
1666
|
} );
|
|
1662
1667
|
const mappedArrays = await Promise.all( promises );
|
|
1663
1668
|
mappedArrays.flat();
|
|
1664
|
-
|
|
1665
|
-
await download( mappedArrays, res );
|
|
1669
|
+
logger.info( { mappedArrays: mappedArrays[0] } );
|
|
1670
|
+
await download( mappedArrays[0], res );
|
|
1666
1671
|
return;
|
|
1667
1672
|
}
|
|
1668
1673
|
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -223,54 +223,17 @@ export const auditDocs = {
|
|
|
223
223
|
},
|
|
224
224
|
},
|
|
225
225
|
'/v3/audit/work-space': {
|
|
226
|
-
|
|
226
|
+
post: {
|
|
227
227
|
tags: [ 'Audit Mapping' ],
|
|
228
228
|
description: 'queue wise info of audit files ',
|
|
229
229
|
operationId: 'work-space',
|
|
230
|
-
|
|
231
|
-
{
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
require: true,
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
in: 'query',
|
|
239
|
-
name: 'searchValue',
|
|
240
|
-
scema: j2s( workSpaceSchema ).swagger,
|
|
241
|
-
require: false,
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
in: 'query',
|
|
245
|
-
name: 'offset',
|
|
246
|
-
scema: j2s( workSpaceSchema ).swagger,
|
|
247
|
-
require: false,
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
in: 'query',
|
|
251
|
-
name: 'limit',
|
|
252
|
-
scema: j2s( workSpaceSchema ).swagger,
|
|
253
|
-
require: false,
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
in: 'query',
|
|
257
|
-
name: 'isExport',
|
|
258
|
-
scema: j2s( workSpaceSchema ).swagger,
|
|
259
|
-
require: false,
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
in: 'query',
|
|
263
|
-
name: 'sortColumnName',
|
|
264
|
-
scema: j2s( workSpaceSchema ).swagger,
|
|
265
|
-
require: false,
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
in: 'query',
|
|
269
|
-
name: 'sortBy',
|
|
270
|
-
scema: j2s( workSpaceSchema ).swagger,
|
|
271
|
-
require: false,
|
|
230
|
+
requestBody: {
|
|
231
|
+
content: {
|
|
232
|
+
'application/json': {
|
|
233
|
+
schema: j2s( workSpaceSchema ).swagger,
|
|
234
|
+
},
|
|
272
235
|
},
|
|
273
|
-
|
|
236
|
+
},
|
|
274
237
|
responses: {
|
|
275
238
|
200: { description: 'Successful' },
|
|
276
239
|
401: { description: 'Unauthorized User' },
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -125,6 +125,7 @@ export const workSpaceSchema = joi.object(
|
|
|
125
125
|
{
|
|
126
126
|
searchValue: joi.string().optional().allow( '' ),
|
|
127
127
|
moduleType: joi.string().required(),
|
|
128
|
+
clientId: joi.array().optional(),
|
|
128
129
|
offset: joi.number().optional(),
|
|
129
130
|
limit: joi.number().optional(),
|
|
130
131
|
isExport: joi.boolean().optional(),
|
|
@@ -134,7 +135,7 @@ export const workSpaceSchema = joi.object(
|
|
|
134
135
|
);
|
|
135
136
|
|
|
136
137
|
export const workSpaceValid = {
|
|
137
|
-
|
|
138
|
+
body: workSpaceSchema,
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
/* < -- *** Audit Metrics *** --> */
|
|
@@ -145,6 +146,7 @@ export const userAuditHistorySchema = joi.object(
|
|
|
145
146
|
fromDate: joi.string().required(),
|
|
146
147
|
toDate: joi.string().required(),
|
|
147
148
|
dateType: joi.string().required(),
|
|
149
|
+
clientId: joi.array().optional(),
|
|
148
150
|
filterByStoreId: joi.array().required(),
|
|
149
151
|
filterByModuleType: joi.array().optional(),
|
|
150
152
|
filterByAuditType: joi.array().optional(),
|
|
@@ -17,7 +17,7 @@ auditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ),
|
|
|
17
17
|
auditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
|
|
18
18
|
auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
|
|
19
19
|
auditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
|
|
20
|
-
auditRouter.
|
|
20
|
+
auditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
|
|
21
21
|
|
|
22
22
|
// Audit Metrics
|
|
23
23
|
auditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
|
package/app.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import { auditRouter } from './index.js';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
import { logger } from 'tango-app-api-middleware';
|
|
5
|
-
import { connectdb } from './config/database/database.js';
|
|
6
|
-
import responseMiddleware from './config/response/response.js';
|
|
7
|
-
import errorMiddleware from './config/response/error.js';
|
|
8
|
-
import pkg from 'body-parser';
|
|
9
|
-
import { swaggerConfig } from './config/swagger/swagger.js';
|
|
10
|
-
import swagger from 'swagger-ui-express';
|
|
11
|
-
|
|
12
|
-
const { json, urlencoded } = pkg;
|
|
13
|
-
const env=dotenv.config();
|
|
14
|
-
|
|
15
|
-
const app = express();
|
|
16
|
-
const PORT = process.env.PORT || 3000;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
app.use( json( { limit: '500mb' } ) );
|
|
20
|
-
app.use(
|
|
21
|
-
urlencoded( {
|
|
22
|
-
extended: true,
|
|
23
|
-
} ),
|
|
24
|
-
);
|
|
25
|
-
app.use( responseMiddleware );
|
|
26
|
-
app.use( errorMiddleware );
|
|
27
|
-
if ( env.error ) {
|
|
28
|
-
logger.error( '.env not found' );
|
|
29
|
-
process.exit( 1 );
|
|
30
|
-
}
|
|
31
|
-
app.use( '/api-docs', swagger.serve, swagger.setup( swaggerConfig ) );
|
|
32
|
-
app.use( '/v3/audit', auditRouter );
|
|
33
|
-
|
|
34
|
-
app.listen( PORT, () => {
|
|
35
|
-
logger.info( `server is running on port= ${PORT} ` );
|
|
36
|
-
connectdb();
|
|
37
|
-
} );
|
|
38
|
-
|