tango-app-api-client 3.6.5-vms.14 → 3.6.5-vms.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,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.15",
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,30 @@ 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}_internal_footfall-directory-tagging`;
116
+ console.log( '🚀 ~ getAuditFile ~ docId:draft', docId );
117
+ const existingDoc = await getOpenSearchById( openSearch.footfallDirectory, docId );
118
+ const ticketSource = existingDoc?.body?._source;
119
+ const currentTime = new Date();
120
+ const updatePayload = {
121
+ doc: {
122
+ status: 'In-Progress',
123
+ updatedAt: currentTime,
124
+ createdByRole: req?.user?.role || '',
125
+ createdByEmail: req?.user?.email || '',
126
+ createdByUserName: req?.user?.userName || '',
127
+ createdByUserId: req?.user?._id || '',
128
+ },
129
+ };
130
+ console.log( '🚀 ~ getAuditFile ~ updatePayload:', updatePayload );
131
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
132
+ if ( ticketSource ) {
133
+ await updateOpenSearchData(
134
+ openSearch.footfallDirectory,
135
+ docId,
136
+ updatePayload,
137
+ );
138
+ }
115
139
  return res.sendSuccess( {
116
140
  result: log.draftedData,
117
141
  storeId: storeDetails?.storeId,
@@ -158,9 +182,34 @@ export async function getAuditFile( req, res ) {
158
182
 
159
183
  };
160
184
  console.log( openSearch.vmsAudit );
161
- let list =inputData.nextId? await scrollResponse( inputData.nextId ): await searchOpenSearchData( openSearch.vmsAudit, query );
185
+ let list = inputData.nextId ? await scrollResponse( inputData.nextId ) : await searchOpenSearchData( openSearch.vmsAudit, query );
186
+
187
+ let docId = `${inputData.storeId}_${inputData.Date}_internal_footfall-directory-tagging`;
188
+ console.log( '🚀 ~ getAuditFile ~ docId:1', docId );
189
+ const existingDoc = await getOpenSearchById( openSearch.footfallDirectory, docId );
190
+ const ticketSource = existingDoc?.body?._source;
191
+ const currentTime = new Date();
192
+ const updatePayload = {
193
+ doc: {
194
+ status: 'In-Progress',
195
+ updatedAt: currentTime,
196
+ createdByRole: req?.user?.role || '',
197
+ createdByEmail: req?.user?.email || '',
198
+ createdByUserName: req?.user?.userName || '',
199
+ createdByUserId: req?.user?._id || '',
200
+ },
201
+ };
202
+ console.log( '🚀 ~ getAuditFile ~ updatePayload:', updatePayload );
203
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
204
+ if ( ticketSource ) {
205
+ await updateOpenSearchData(
206
+ openSearch.footfallDirectory,
207
+ docId,
208
+ updatePayload,
209
+ );
210
+ }
162
211
  const folderPath = list?.body?.hits?.hits;
163
- if ( list?.body?.hits?.hits?.length ==0 ) {
212
+ if ( list?.body?.hits?.hits?.length == 0 ) {
164
213
  await clearScroll( list?.body?._scroll_id );
165
214
  }
166
215
  if ( folderPath?.length > 0 ) {
@@ -238,7 +287,7 @@ export async function getAuditFile( req, res ) {
238
287
  Date: inputData.Date,
239
288
  auditId: insertData._id,
240
289
  userId: insertData.userId,
241
- nextToken: list?.body?._scroll_id ?list?.body?._scroll_id:null,
290
+ nextToken: list?.body?._scroll_id ? list?.body?._scroll_id : null,
242
291
 
243
292
  },
244
293
  isDraft: insertData.isDraft,
@@ -343,3 +392,53 @@ export async function getDraftedData( req, res ) {
343
392
  return res.sendError( err, 500 );
344
393
  }
345
394
  }
395
+
396
+
397
+ export async function reAssignAudit( req, res ) {
398
+ try {
399
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
400
+ let inputData = req.body;
401
+ let docId = `${inputData.storeId}_${inputData.dateString}_internal_footfall-directory-tagging`;
402
+ console.log( '🚀 ~ getAuditFile ~ docId:draft', docId );
403
+ const existingDoc = await getOpenSearchById( openSearch.footfallDirectory, docId );
404
+ const ticketSource = existingDoc?.body?._source;
405
+ const currentTime = new Date();
406
+ const userdata = await findOneUser( { email: inputData.email } );
407
+ const updatePayload = {
408
+ doc: {
409
+ status: 'In-Progress',
410
+ updatedAt: currentTime,
411
+ createdByRole: userdata?.role || '',
412
+ createdByEmail: userdata?.email || '',
413
+ createdByUserName: userdata?.userName || '',
414
+ createdByUserId: userdata?._id || '',
415
+ },
416
+ };
417
+ console.log( '🚀 ~ getAuditFile ~ updatePayload:', updatePayload );
418
+ console.log( '🚀 ~ getAuditFile ~ ticketSource:', ticketSource );
419
+ if ( ticketSource ) {
420
+ await updateOpenSearchData(
421
+ openSearch.footfallDirectory,
422
+ docId,
423
+ updatePayload,
424
+ );
425
+ }
426
+
427
+ await updatemanyvmsUserAudit(
428
+ { auditStatus: { $ne: 'completed', storeId: inputData.storeId, fileDate: inputData.dateString } },
429
+ { status: 'skipped' } );
430
+
431
+
432
+ return res.sendSuccess( 'Ticket Reassigned Successfully' );
433
+ } catch ( error ) {
434
+ const err = error.message || 'Internal Server Error';
435
+ logger.error( {
436
+ error: error,
437
+ message: req.query,
438
+ function: 'reAssignAudit',
439
+ } );
440
+ return res.sendError( err, 500 );
441
+ }
442
+ }
443
+
444
+
@@ -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 );