tango-app-api-audit 3.3.0-alpha.13 → 3.3.0-alpha.15

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,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.3.0-alpha.13",
3
+ "version": "3.3.0-alpha.15",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "mongodb": "^6.7.0",
25
25
  "nodemon": "^3.1.3",
26
26
  "swagger-ui-express": "^5.0.1",
27
- "tango-api-schema": "^2.0.154",
27
+ "tango-api-schema": "^2.0.157",
28
28
  "tango-app-api-middleware": "^3.3.0-alpha.0",
29
29
  "winston": "^3.13.0",
30
30
  "winston-daily-rotate-file": "^5.0.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.query;
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
- query.push( {
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
- 'Client ID': element.clientId,
1643
- 'Client Name': element.clientName,
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
 
@@ -1978,7 +1983,7 @@ export async function storeMetrics( req, res ) {
1978
1983
  _id: 0,
1979
1984
  fileDate: 1,
1980
1985
  storeId: 1,
1981
- storeName: '$store.storeName',
1986
+ storeName: '$stores.storeName',
1982
1987
  clientName: '',
1983
1988
  clientId: 1,
1984
1989
  zoneName: 1,
@@ -2060,7 +2065,7 @@ export async function storeMetrics( req, res ) {
2060
2065
  _id: 0,
2061
2066
  fileDate: 1,
2062
2067
  storeId: 1,
2063
- storeName: '$stores.storeName',
2068
+ storeName: 1,
2064
2069
  userName: '$users.userName',
2065
2070
  userEmail: '$users.userEmail',
2066
2071
  clientId: 1,
@@ -2419,9 +2424,8 @@ export async function userMetrics( req, res ) {
2419
2424
  '_id': 0,
2420
2425
  'File Date': '$fileDate',
2421
2426
  'User Name': '$userName',
2422
- 'User Id': '$userId',
2423
2427
  'Total Completed Files Count': '$totalCompletedFiles',
2424
- 'Total efore Count': '$beforeCount',
2428
+ 'Total Before Count': '$beforeCount',
2425
2429
  'Total After Count': '$afterCount',
2426
2430
  'check Intime': '$checkIntime',
2427
2431
  'check OutTime': '$checkOutTime',
@@ -2440,7 +2444,7 @@ export async function userMetrics( req, res ) {
2440
2444
  return res.sendSuccess( { result: result, count: count.length } );
2441
2445
  } catch ( error ) {
2442
2446
  const err = error.error || 'Internal Server Error';
2443
- logger.info( { error: error, message: req.body, function: 'clientMetrics' } );
2447
+ logger.info( { error: error, message: req.body, function: 'userMetrics' } );
2444
2448
  return res.sendError( err, 500 );
2445
2449
  }
2446
2450
  }
@@ -2725,7 +2729,7 @@ export async function overAllAuditSummary( req, res ) {
2725
2729
  return res.sendSuccess( { result: temp } );
2726
2730
  } catch ( error ) {
2727
2731
  const err = error.message || 'Internal Server Error';
2728
- logger.error( { error: error, message: req.body, function: 'summarySplit' } );
2732
+ logger.error( { error: error, message: req.body, function: 'overAllAuditSummary' } );
2729
2733
  return res.sendError( err, 500 );
2730
2734
  }
2731
2735
  }
@@ -2873,7 +2877,7 @@ export async function reTrigger( req, res ) {
2873
2877
  return res.sendSuccess( { result: 'The File has been Re Trigger Succesfully' } );
2874
2878
  } catch ( error ) {
2875
2879
  const err = error.message;
2876
- logger.error( { error: error, message: req.body } );
2880
+ logger.error( { error: error, message: req.body, function: 'reTrigger' } );
2877
2881
  return res.sendError( err, 500 );
2878
2882
  }
2879
2883
  }
@@ -3254,6 +3258,117 @@ export async function overviewTable( req, res ) {
3254
3258
  }
3255
3259
  }
3256
3260
 
3261
+ export async function totalNotAssignedCount( req, res ) {
3262
+ try {
3263
+ let notAssignedCount = {
3264
+ totalAuditCount: 0,
3265
+ totalZoneCount: 0,
3266
+ totalTrafficCount: 0,
3267
+ };
3268
+ const getStoreData = await findOneStoreData(
3269
+ {},
3270
+ { fileDate: 1 },
3271
+ { createdAt: -1 },
3272
+ );
3273
+ const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
3274
+ const query =[
3275
+ {
3276
+ $match: {
3277
+ fileDate: { $eq: latestDate },
3278
+ },
3279
+ },
3280
+ {
3281
+ $project: {
3282
+ totalZoneCount: { $cond: [
3283
+ { $eq: [ '$moduleType', 'zone' ] }, 1, 0,
3284
+ ] },
3285
+ totalTrafficCount: { $cond: [
3286
+ { $eq: [ '$moduleType', 'traffic' ] }, 1, 0,
3287
+ ] },
3288
+
3289
+ },
3290
+ },
3291
+ {
3292
+ $group: {
3293
+ _id: null,
3294
+ totalAuditCount: { $sum: 1 },
3295
+ totalZoneCount: { $sum: '$totalZoneCount' },
3296
+ totalTrafficCount: { $sum: '$totalTrafficCount' },
3297
+
3298
+ },
3299
+ },
3300
+ {
3301
+ $project: {
3302
+ _id: 0,
3303
+ totalAuditCount: 1,
3304
+ totalZoneCount: 1,
3305
+ totalTrafficCount: 1,
3306
+ },
3307
+ },
3308
+ ];
3309
+ const inprogressCount=[
3310
+ {
3311
+ $match: {
3312
+ fileDate: { $eq: latestDate },
3313
+ },
3314
+ },
3315
+ {
3316
+ $project: {
3317
+ inprogressAuditCount: {
3318
+ $cond: [
3319
+ { $in: [ '$status', [ 'completed', 'not_assign' ] ] }, 1, 0,
3320
+ ],
3321
+ },
3322
+ inprogressZoneCount: { $cond: [
3323
+ { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign' ] ] } ] }, 1, 0,
3324
+ ] },
3325
+ inprogressTrafficCount: { $cond: [
3326
+ { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign' ] ] } ] }, 1, 0,
3327
+ ] },
3328
+
3329
+ },
3330
+ },
3331
+ {
3332
+ $group: {
3333
+ _id: null,
3334
+ inprogressAuditCount: { $sum: '$inprogressAuditCount' },
3335
+ inprogressZoneCount: { $sum: '$inprogressZoneCount' },
3336
+ inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
3337
+
3338
+ },
3339
+ },
3340
+ {
3341
+ $project: {
3342
+ _id: 0,
3343
+ inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
3344
+ inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
3345
+ inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
3346
+ },
3347
+ },
3348
+ ];
3349
+ const getTotalcount = await aggregateAuditStoreData( query );
3350
+
3351
+ const getInprogressCount = await aggregateStoreAudit( inprogressCount );
3352
+ if ( getTotalcount.length == 0 ) {
3353
+ return res.sendError( 'No Data Found', 204 );
3354
+ }
3355
+
3356
+ if ( getInprogressCount.length >0 ) {
3357
+ notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount;
3358
+ notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount;
3359
+ notAssignedCount.totalTrafficCount = getTotalcount[0].totalTrafficCount - getInprogressCount[0]?.inprogressTrafficCount;
3360
+ } else {
3361
+ notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount;
3362
+ notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount;
3363
+ notAssignedCount.totalTrafficCount;
3364
+ }
3365
+ return res.sendSuccess( { result: notAssignedCount } );
3366
+ } catch ( error ) {
3367
+ const err = error.message || 'Internal Server Error';
3368
+ logger.info( { error: error, message: req.body, function: 'totalNotAssignedCount' } );
3369
+ return res.sendError( err, 500 );
3370
+ }
3371
+ }
3257
3372
 
3258
3373
  export async function auditImages( req, res ) {
3259
3374
  try {
@@ -3321,7 +3436,7 @@ export async function auditImages( req, res ) {
3321
3436
  // return res.sendSuccess( { result: inputData } );
3322
3437
  } catch ( error ) {
3323
3438
  const err = error.message || 'Internal Server Error';
3324
- logger.info( { error: error, message: req.body, function: 'beforeCountImages' } );
3439
+ logger.info( { error: error, message: req.body, function: 'auditImages' } );
3325
3440
  return res.sendError( err, 500 );
3326
3441
  }
3327
3442
  }
@@ -223,54 +223,17 @@ export const auditDocs = {
223
223
  },
224
224
  },
225
225
  '/v3/audit/work-space': {
226
- get: {
226
+ post: {
227
227
  tags: [ 'Audit Mapping' ],
228
228
  description: 'queue wise info of audit files ',
229
229
  operationId: 'work-space',
230
- parameters: [
231
- {
232
- in: 'query',
233
- name: 'moduleType',
234
- scema: j2s( workSpaceSchema ).swagger,
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' },
@@ -561,4 +524,18 @@ export const auditDocs = {
561
524
 
562
525
  },
563
526
  },
527
+ '/v3/audit/total-not-assigned-count': {
528
+ get: {
529
+ tags: [ 'Audit Mapping' ],
530
+ description: 'Get total Not Assigned Count',
531
+ operationId: 'clients',
532
+ responses: {
533
+ 200: { description: 'Successful' },
534
+ 401: { description: 'Unauthorized User' },
535
+ 422: { description: 'Field Error' },
536
+ 500: { description: 'Server Error' },
537
+ 204: { description: 'Not Found' },
538
+ },
539
+ },
540
+ },
564
541
  };
@@ -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
- query: workSpaceSchema,
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(),
@@ -1,7 +1,7 @@
1
1
  import express from 'express';
2
2
  import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/audit.controllers.js';
4
+ import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace } from '../controllers/audit.controllers.js';
5
5
  import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
6
6
 
7
7
  export const auditRouter = express.Router();
@@ -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.get( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
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 );
@@ -33,4 +33,6 @@ auditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, validate( o
33
33
  auditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
34
34
  auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
35
35
 
36
+ // ticket
37
+ auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
36
38
  export default auditRouter;