tango-app-api-audit 1.0.33 → 1.0.34

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": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1211,7 +1211,7 @@ export async function reTrigger( req, res ) {
1211
1211
  }
1212
1212
 
1213
1213
  const storeRecord ={
1214
- status: userAudit?.auditStatus !== 'completed' ? 'skipped': 'not_assign',
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: userAudit?.auditStatus !== 'completed' ? 'skipped': 'assigned',
1269
+ status: req.audit.status !== 'completed' ? 'skipped': 'assigned',
1270
1270
  };
1271
1271
 
1272
1272
  await updateOneStoreAudit( query, storeRecord );
@@ -1,5 +1,5 @@
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';
@@ -43,7 +43,6 @@ export async function getZoneAuditFile( req, res ) {
43
43
 
44
44
  switch ( zoneAuditStatus ) {
45
45
  case null:
46
-
47
46
  const query = [
48
47
  {
49
48
  $match: {
@@ -82,6 +81,22 @@ export async function getZoneAuditFile( req, res ) {
82
81
  }
83
82
  break;
84
83
 
84
+ // case 'drafted':
85
+ // logger.info( 'userDetails drafted', { inputData } );
86
+
87
+ // const log = await findOneAuditLog(
88
+ // {
89
+ // userId: userDetails[0].userId,
90
+ // fileDate: userDetails[0].fileDate,
91
+ // storeId: userDetails[0].storeId,
92
+ // totalCount: userDetails[0].beforeCount,
93
+
94
+ // },
95
+ // {},
96
+ // { createdAt: -1 },
97
+ // );
98
+
99
+
85
100
  default:
86
101
  msg = {
87
102
  store_id: userDetails[0].storeId,
@@ -253,3 +268,74 @@ export async function getZoneAuditFile( req, res ) {
253
268
  return res.sendError( error, 500 );
254
269
  }
255
270
  }
271
+
272
+ export async function saveDraft( req, res ) {
273
+ try {
274
+ // const openSearch = JSON.parse( process.env.OPENSEARCH );
275
+ const inputData = req.body;
276
+ inputData.userId = req.user._id;
277
+ const getUserAuditData = await findOneZoneUserAudit( { _id: inputData.auditId } );
278
+ if ( !getUserAuditData ) {
279
+ return res.sendError( 'No Data Found', 204 );
280
+ }
281
+ if ( getUserAuditData.auditStatus == 'skipped' ) {
282
+ return res.sendError( 'File Assigned to Someone else', 203 );
283
+ }
284
+
285
+ // const userQuery = {
286
+ // _id: inputData.auditId,
287
+ // };
288
+ // let userRecord = {
289
+ // isDraft: true,
290
+ // auditStatus: 'drafted',
291
+ // };
292
+ // const storeQuery = {
293
+ // storeId: inputData.storeId,
294
+ // fileDate: inputData.fileDate,
295
+ // };
296
+
297
+ let storeRecord = {
298
+ status: 'drafted',
299
+ };
300
+
301
+ if ( getUserAuditData?.startTime ) {
302
+ const isoDate = getUserAuditData.startTime;
303
+ const currentTime = dayjs();
304
+ const isoDateTime = dayjs( isoDate );
305
+ const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
306
+
307
+ userRecord.timeSpent = timeDifferenceInMinutes;
308
+
309
+ storeRecord.timeSpent = timeDifferenceInMinutes;
310
+ }
311
+
312
+ // if ( inputData.userCommands ) {
313
+ // userRecord.userCommands = inputData.userCommands;
314
+ // const logData = {
315
+ // userId: req.user._id,
316
+ // userName: req.user.userName,
317
+ // logType: 'audit',
318
+ // logSubType: 'auditDraft',
319
+ // logData: {
320
+ // auditType: inputData.auditType,
321
+ // storeId: inputData.storeId,
322
+ // clientName: inputData.queueName,
323
+ // beforeCount: inputData.totalCount,
324
+ // afterCount: inputData.customerCount,
325
+ // auditId: inputData.auditId,
326
+ // },
327
+ // };
328
+ // await insertOpenSearchData( openSearch.activityLog, logData );
329
+ // }
330
+ // await createAuditLog( inputData );
331
+ // await updateOneUserAudit( userQuery, userRecord );
332
+ // await updateOneStoreAudit( storeQuery, storeRecord );
333
+ // return res.sendSuccess( {
334
+ // result: 'The file has been drafted successfully',
335
+ // } );
336
+ } catch ( error ) {
337
+ const err = error.message || 'Internal Server Error';
338
+ logger.error( { error: error, message: req.body, function: 'saveDraft' } );
339
+ return res.sendError( err, 500 );
340
+ }
341
+ }
@@ -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
- // '/v3/audit/save-draft': {
40
- // post: {
41
- // tags: [ 'Audit' ],
42
- // description: `save 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
- // },
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 );