tango-app-api-audit 1.0.34 → 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.34",
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 . && node index.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && app index.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -5,10 +5,12 @@ 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;
@@ -271,7 +273,7 @@ export async function getZoneAuditFile( req, res ) {
271
273
 
272
274
  export async function saveDraft( req, res ) {
273
275
  try {
274
- // const openSearch = JSON.parse( process.env.OPENSEARCH );
276
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
275
277
  const inputData = req.body;
276
278
  inputData.userId = req.user._id;
277
279
  const getUserAuditData = await findOneZoneUserAudit( { _id: inputData.auditId } );
@@ -282,17 +284,17 @@ export async function saveDraft( req, res ) {
282
284
  return res.sendError( 'File Assigned to Someone else', 203 );
283
285
  }
284
286
 
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
- // };
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
+ };
296
298
 
297
299
  let storeRecord = {
298
300
  status: 'drafted',
@@ -309,30 +311,30 @@ export async function saveDraft( req, res ) {
309
311
  storeRecord.timeSpent = timeDifferenceInMinutes;
310
312
  }
311
313
 
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
- // } );
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
+ } );
336
338
  } catch ( error ) {
337
339
  const err = error.message || 'Internal Server Error';
338
340
  logger.error( { error: error, message: req.body, function: 'saveDraft' } );