tango-app-api-client 3.6.5-vms.14 → 3.6.5-vms.16

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-client",
3
- "version": "3.6.5-vms.14",
3
+ "version": "3.6.5-vms.16",
4
4
  "description": "client",
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 . && node app.js\"",
9
9
  "build:patch": "node build.js patch && npm publish",
10
10
  "build:minor": "node build.js minor && npm publish",
11
11
  "build:major": "node build.js major && npm publish"
@@ -1,6 +1,6 @@
1
- import { logger, searchOpenSearchData } from 'tango-app-api-middleware';
1
+ import { logger, searchOpenSearchData, getOpenSearchById, updateOpenSearchData } from 'tango-app-api-middleware';
2
2
  import { findOneStore } from '../service/store.service.js';
3
- import { aggregatevmsUserAudit, createvmsUserAudit, findOnevmsUserAudit, updateOnevmsUserAudit } from '../service/vmsuserAudit.service.js';
3
+ import { aggregatevmsUserAudit, createvmsUserAudit, findOnevmsUserAudit, updateOnevmsUserAudit, updatemanyvmsUserAudit } from '../service/vmsuserAudit.service.js';
4
4
  import { createvmsAuditLog, findOnevmsAuditLog } from '../service/vmsauditLog.service.js';
5
5
  import { insertOpenSearchData, clearScroll, scrollResponse } from 'tango-app-api-middleware';
6
6
  import { findOneUser } from '../service/user.service.js';
@@ -112,6 +112,50 @@ export async function getAuditFile( req, res ) {
112
112
  address: '$storeProfile.address',
113
113
  };
114
114
  const storeDetails = await findOneStore( storeQuery, storeFields );
115
+ let docId = `${inputData.storeId}_${inputData.Date}_footfall-directory-tagging`;
116
+ if ( inputData.tickettype === 'internal' ) {
117
+ docId = `${inputData.storeId}_${inputData.Date}_internal_footfall-directory-tagging`;
118
+ }
119
+ console.log( '🚀 ~ getAuditFile ~ docId:draft', docId );
120
+ const existinginternalDoc = await getOpenSearchById( openSearch.footfallDirectory, docId );
121
+ let ticketSource = existinginternalDoc?.body?._source;
122
+ const currentTime = new Date();
123
+ const updatePayload = {
124
+ doc: {
125
+ status: 'In-Progress',
126
+ updatedAt: currentTime,
127
+ createdByRole: req?.user?.role || '',
128
+ createdByEmail: req?.user?.email || '',
129
+ createdByUserName: req?.user?.userName || '',
130
+ createdByUserId: req?.user?._id || '',
131
+ },
132
+ };
133
+ console.log( '🚀 ~ getAuditFile ~ updatePayload:', updatePayload );
134
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
135
+ if ( ticketSource && inputData.tickettype === 'store' ) {
136
+ ticketSource.mappingInfo.map( ( data ) => {
137
+ if ( data.type === 'tangoreview' ) {
138
+ data.status = 'In-Progress';
139
+ }
140
+ } );
141
+ ticketSource.createdByRole = req?.user?.role || '';
142
+ ticketSource.createdByEmail = req?.user?.email || '';
143
+ ticketSource.createdByUserName = req?.user?.userName || '';
144
+ ticketSource.createdByUserId = req?.user?._id || '';
145
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
146
+ await updateOpenSearchData(
147
+ openSearch.footfallDirectory,
148
+ docId,
149
+ { doc: ticketSource },
150
+
151
+ );
152
+ } else if ( ticketSource && inputData.tickettype === 'internal' ) {
153
+ await updateOpenSearchData(
154
+ openSearch.footfallDirectory,
155
+ docId,
156
+ updatePayload,
157
+ );
158
+ }
115
159
  return res.sendSuccess( {
116
160
  result: log.draftedData,
117
161
  storeId: storeDetails?.storeId,
@@ -158,9 +202,54 @@ export async function getAuditFile( req, res ) {
158
202
 
159
203
  };
160
204
  console.log( openSearch.vmsAudit );
161
- let list =inputData.nextId? await scrollResponse( inputData.nextId ): await searchOpenSearchData( openSearch.vmsAudit, query );
205
+ let list = inputData.nextId ? await scrollResponse( inputData.nextId ) : await searchOpenSearchData( openSearch.vmsAudit, query );
206
+
207
+ let docId = `${inputData.storeId}_${inputData.Date}_footfall-directory-tagging`;
208
+ if ( inputData.tickettype === 'internal' ) {
209
+ docId = `${inputData.storeId}_${inputData.Date}_internal_footfall-directory-tagging`;
210
+ }
211
+ console.log( '🚀 ~ getAuditFile ~ docId:draft', docId );
212
+ const existinginternalDoc = await getOpenSearchById( openSearch.footfallDirectory, docId );
213
+ let ticketSource = existinginternalDoc?.body?._source;
214
+ const currentTime = new Date();
215
+ const updatePayload = {
216
+ doc: {
217
+ status: 'In-Progress',
218
+ updatedAt: currentTime,
219
+ createdByRole: req?.user?.role || '',
220
+ createdByEmail: req?.user?.email || '',
221
+ createdByUserName: req?.user?.userName || '',
222
+ createdByUserId: req?.user?._id || '',
223
+ },
224
+ };
225
+ console.log( '🚀 ~ getAuditFile ~ updatePayload:', updatePayload );
226
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
227
+ if ( ticketSource && inputData.tickettype != 'internal' ) {
228
+ ticketSource.mappingInfo.map( ( data ) => {
229
+ if ( data.type === 'tangoreview' ) {
230
+ data.status = 'In-Progress';
231
+ console.log( '🚀 ~ getAuditFile ~ data.status:', data.status );
232
+ }
233
+ } );
234
+ ticketSource.createdByRole = req?.user?.role || '';
235
+ ticketSource.createdByEmail = req?.user?.email || '';
236
+ ticketSource.createdByUserName = req?.user?.userName || '';
237
+ ticketSource.createdByUserId = req?.user?._id || '';
238
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
239
+ await updateOpenSearchData(
240
+ openSearch.footfallDirectory,
241
+ docId,
242
+ { doc: ticketSource },
243
+ );
244
+ } else if ( ticketSource && inputData.tickettype === 'internal' ) {
245
+ await updateOpenSearchData(
246
+ openSearch.footfallDirectory,
247
+ docId,
248
+ updatePayload,
249
+ );
250
+ }
162
251
  const folderPath = list?.body?.hits?.hits;
163
- if ( list?.body?.hits?.hits?.length ==0 ) {
252
+ if ( list?.body?.hits?.hits?.length == 0 ) {
164
253
  await clearScroll( list?.body?._scroll_id );
165
254
  }
166
255
  if ( folderPath?.length > 0 ) {
@@ -238,7 +327,7 @@ export async function getAuditFile( req, res ) {
238
327
  Date: inputData.Date,
239
328
  auditId: insertData._id,
240
329
  userId: insertData.userId,
241
- nextToken: list?.body?._scroll_id ?list?.body?._scroll_id:null,
330
+ nextToken: list?.body?._scroll_id ? list?.body?._scroll_id : null,
242
331
 
243
332
  },
244
333
  isDraft: insertData.isDraft,
@@ -343,3 +432,57 @@ export async function getDraftedData( req, res ) {
343
432
  return res.sendError( err, 500 );
344
433
  }
345
434
  }
435
+
436
+
437
+ export async function reAssignAudit( req, res ) {
438
+ try {
439
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
440
+ let inputData = req.body;
441
+ let docId = `${inputData.storeId}_${inputData.dateString}_internal_footfall-directory-tagging`;
442
+ if ( inputData.tickettype ==='store' ) {
443
+ docId = `${inputData.storeId}_${inputData.dateString}_footfall-directory-tagging`;
444
+ }
445
+ console.log( '🚀 ~ getAuditFile ~ docId:draft', docId );
446
+ const existingDoc = await getOpenSearchById( openSearch.footfallDirectory, docId );
447
+ const ticketSource = existingDoc?.body?._source;
448
+ const currentTime = new Date();
449
+ const userdata = await findOneUser( { email: inputData.email } );
450
+ const updatePayload = {
451
+ doc: {
452
+ status: 'In-Progress',
453
+ updatedAt: currentTime,
454
+ createdByRole: userdata?.role || '',
455
+ createdByEmail: userdata?.email || '',
456
+ createdByUserName: userdata?.userName || '',
457
+ createdByUserId: userdata?._id || '',
458
+ },
459
+ };
460
+ console.log( '🚀 ~ getAuditFile ~ updatePayload:', updatePayload );
461
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
462
+ if ( ticketSource ) {
463
+ await updateOpenSearchData(
464
+ openSearch.footfallDirectory,
465
+ docId,
466
+ updatePayload,
467
+ );
468
+ }
469
+
470
+ console.log( '🚀 ~ reAssignAudit ~ inputData.dateString:', inputData.dateString );
471
+ await updatemanyvmsUserAudit(
472
+ { auditStatus: { $ne: 'completed' }, storeId: inputData.storeId, fileDate: inputData.dateString },
473
+ { status: 'skipped' } );
474
+
475
+
476
+ return res.sendSuccess( 'Ticket Reassigned Successfully' );
477
+ } catch ( error ) {
478
+ const err = error.message || 'Internal Server Error';
479
+ logger.error( {
480
+ error: error,
481
+ message: req.query,
482
+ function: 'reAssignAudit',
483
+ } );
484
+ return res.sendError( err, 500 );
485
+ }
486
+ }
487
+
488
+
@@ -12,6 +12,7 @@ export const getFileSchema = joi.object( {
12
12
  storeId: joi.string().required(),
13
13
  Date: joi.string().required(),
14
14
  count: joi.string().required(),
15
+ tickettype: joi.string().required(),
15
16
  } );
16
17
 
17
18
 
@@ -1,10 +1,11 @@
1
1
  import express from 'express';
2
2
  import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
3
  import { getDraftedDataValid, getFileValid } from '../dtos/vmsAudit.dtos.js';
4
- import { getAuditFile, getDraftedData, saveDraft } from '../controllers/vmsAudit.controller.js';
4
+ import { getAuditFile, getDraftedData, saveDraft, reAssignAudit } from '../controllers/vmsAudit.controller.js';
5
5
  export const vmsauditRouter = express.Router();
6
6
 
7
7
 
8
8
  vmsauditRouter.get( '/get-file', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getFileValid ), getAuditFile );
9
9
  vmsauditRouter.post( '/save-draft', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), saveDraft );
10
10
  vmsauditRouter.get( '/get-drafted-data', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getDraftedDataValid ), getDraftedData );
11
+ vmsauditRouter.post( '/reAssign-audit', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), reAssignAudit );
@@ -8,6 +8,9 @@ export function aggregatevmsUserAudit( query ) {
8
8
  export function updateOnevmsUserAudit( query, record ) {
9
9
  return vmsuserAuditModel.updateOne( query, { $set: record } );
10
10
  }
11
+ export function updatemanyvmsUserAudit( query, record ) {
12
+ return vmsuserAuditModel.updateMany( query, { $set: record } );
13
+ }
11
14
 
12
15
  export function createvmsUserAudit( record ) {
13
16
  return vmsuserAuditModel.create( record );