tango-app-api-infra 3.9.5-vms.7 → 3.9.5-vms.8
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-infra",
|
|
3
|
-
"version": "3.9.5-vms.
|
|
3
|
+
"version": "3.9.5-vms.8",
|
|
4
4
|
"description": "infra",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"mongodb": "^6.4.0",
|
|
28
28
|
"nodemon": "^3.1.0",
|
|
29
29
|
"swagger-ui-express": "^5.0.0",
|
|
30
|
-
"tango-api-schema": "^2.4.
|
|
30
|
+
"tango-api-schema": "^2.4.28",
|
|
31
31
|
"tango-app-api-middleware": "^3.1.93",
|
|
32
32
|
"winston": "^3.12.0",
|
|
33
33
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -228,14 +228,13 @@ export async function ticketCreation( req, res, next ) {
|
|
|
228
228
|
// check the createtion permission from the user permission
|
|
229
229
|
const userInfo = req?.user;
|
|
230
230
|
const ticketsFeature = userInfo?.rolespermission?.some( ( f ) => f.featureName === 'FootfallDirectory' && ( f.modules.find( ( m ) => m.name =='creator' && ( m.isAdd==true || m.isEdit==true ) ) ) );
|
|
231
|
-
logger.info( { ticketsFeature } );
|
|
232
231
|
if ( !ticketsFeature ) {
|
|
233
232
|
return res.sendError( 'Forbidden to Create Ticket', 403 );
|
|
234
233
|
}
|
|
235
234
|
|
|
236
235
|
// get store info by the storeId into mongo db
|
|
237
236
|
const getstoreName = await findOneStore( { storeId: inputData.storeId, status: 'active' }, { storeId: 1, storeName: 1, clientId: 1 } );
|
|
238
|
-
|
|
237
|
+
|
|
239
238
|
if ( !getstoreName || getstoreName == null ) {
|
|
240
239
|
return res.sendError( 'The store ID is either inActive or not found', 400 );
|
|
241
240
|
}
|
|
@@ -261,22 +260,20 @@ export async function ticketCreation( req, res, next ) {
|
|
|
261
260
|
|
|
262
261
|
const getFootfallCount = await getOpenSearchData( openSearch.footfall, getQuery );
|
|
263
262
|
const hits = getFootfallCount?.body?.hits?.hits || [];
|
|
264
|
-
logger.info( { hits } );
|
|
265
263
|
if ( hits?.[0]?._source?.footfall_count <= 0 ) {
|
|
266
264
|
return res.sendError( 'You can’t create a ticket because this store has 0 footfall data' );
|
|
267
265
|
}
|
|
268
266
|
|
|
269
267
|
// get category details from the client level configuration
|
|
270
268
|
const getConfig = await findOneClient( { clientId: getstoreName.clientId }, { footfallDirectoryConfigs: 1 } );
|
|
271
|
-
logger.info( { getConfig, ta123: getConfig?.footfallDirectoryConfigs } );
|
|
272
269
|
if ( !getConfig || getConfig == null ) {
|
|
273
270
|
return res.sendError( 'The Client ID is either not configured or not found', 400 );
|
|
274
271
|
}
|
|
275
272
|
|
|
276
273
|
// Get taggingLimitation from config (check both possible paths)
|
|
277
274
|
const taggingLimitation = getConfig?.footfallDirectoryConfigs?.taggingLimitation;
|
|
278
|
-
logger.info( { taggingLimitation, tagginngs: getConfig?.footfallDirectoryConfigs } );
|
|
279
275
|
// Initialize count object from taggingLimitation
|
|
276
|
+
const tempAcc = [];
|
|
280
277
|
const getCategory = taggingLimitation?.reduce( ( acc, item ) => {
|
|
281
278
|
if ( item?.type ) {
|
|
282
279
|
// Convert type to camelCase with "Count" suffix
|
|
@@ -289,11 +286,21 @@ export async function ticketCreation( req, res, next ) {
|
|
|
289
286
|
// Convert first letter to lowercase and append "Count"
|
|
290
287
|
key = typeLower.charAt( 0 ) + typeLower.slice( 1 ) + 'Count';
|
|
291
288
|
}
|
|
292
|
-
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
// To change from an object to the desired array structure, assemble an array of objects:
|
|
292
|
+
tempAcc.push( {
|
|
293
|
+
name: item.name,
|
|
294
|
+
value: 0,
|
|
295
|
+
key: key,
|
|
296
|
+
type: item.type,
|
|
297
|
+
} );
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
return acc;
|
|
293
301
|
}
|
|
294
|
-
return acc;
|
|
295
302
|
}, {} ) || {};
|
|
296
|
-
|
|
303
|
+
|
|
297
304
|
// Query OpenSearch revop index to get actual counts for each type
|
|
298
305
|
if ( taggingLimitation && taggingLimitation.length > 0 ) {
|
|
299
306
|
const revopQuery = {
|
|
@@ -324,51 +331,38 @@ export async function ticketCreation( req, res, next ) {
|
|
|
324
331
|
},
|
|
325
332
|
};
|
|
326
333
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
//
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
} else if ( revopsType === 'housekeeping' ) {
|
|
348
|
-
if ( getCategory.hasOwnProperty( 'houseKeepingCount' ) ) {
|
|
349
|
-
getCategory.houseKeepingCount = count;
|
|
350
|
-
}
|
|
351
|
-
} else if ( revopsType === 'junk' ) {
|
|
352
|
-
if ( getCategory.hasOwnProperty( 'junkCount' ) ) {
|
|
353
|
-
getCategory.junkCount = count;
|
|
354
|
-
}
|
|
334
|
+
|
|
335
|
+
const revopData = await getOpenSearchData( openSearch.revop, revopQuery );
|
|
336
|
+
const buckets = revopData?.body?.aggregations?.type_counts?.buckets || [];
|
|
337
|
+
|
|
338
|
+
// Map OpenSearch revopsType values to count object keys
|
|
339
|
+
buckets.forEach( ( bucket ) => {
|
|
340
|
+
const revopsType = bucket.key;
|
|
341
|
+
const count = bucket.doc_count || 0;
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
if ( Array.isArray( tempAcc ) ) {
|
|
345
|
+
// Find the tempAcc entry whose type (case-insensitive) matches revopsType
|
|
346
|
+
const accMatch = tempAcc.find(
|
|
347
|
+
( acc ) =>
|
|
348
|
+
acc.type &&
|
|
349
|
+
acc.type === revopsType,
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
if ( accMatch && accMatch.key ) {
|
|
353
|
+
tempAcc.find( ( a ) => a.key === accMatch.key ).value = count;
|
|
355
354
|
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
logger.error( { error: error, message: 'Error fetching revop counts', function: 'footfallDirectoryTicket-ticketCreation' } );
|
|
359
|
-
// Continue with default 0 values if query fails
|
|
360
|
-
}
|
|
355
|
+
}
|
|
356
|
+
} );
|
|
361
357
|
}
|
|
362
358
|
|
|
363
|
-
logger.info( { getCategory: getCategory } );
|
|
364
359
|
|
|
365
360
|
// Calculate revisedFootfall: footfallCount - (sum of all counts)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
361
|
+
|
|
362
|
+
const totalCount = Array.isArray( tempAcc ) ?
|
|
363
|
+
tempAcc.reduce( ( sum, acc ) => sum + ( acc.value || 0 ), 0 ) :
|
|
364
|
+
0;
|
|
370
365
|
const footfallCount = hits?.[0]?._source?.footfall_count || 0;
|
|
371
|
-
logger.info( { footfallCount, totalCount } );
|
|
372
366
|
const revisedFootfall = Math.max( 0, footfallCount - totalCount );
|
|
373
367
|
if ( footfallCount - revisedFootfall == 0 ) {
|
|
374
368
|
return res.sendError( 'Cannot create a ticket because footfall hasn’t changed', 400 );
|
|
@@ -400,7 +394,6 @@ export async function ticketCreation( req, res, next ) {
|
|
|
400
394
|
return res.sendError( 'You don’t have any tagged images right now', 400 );
|
|
401
395
|
}
|
|
402
396
|
const formattedTaggingData = formatRevopTaggingHits( taggingImages );
|
|
403
|
-
logger.info( { revopTaggingData: formattedTaggingData } );
|
|
404
397
|
|
|
405
398
|
const record = {
|
|
406
399
|
storeId: inputData.storeId,
|
|
@@ -420,12 +413,13 @@ export async function ticketCreation( req, res, next ) {
|
|
|
420
413
|
type: 'tagging',
|
|
421
414
|
mode: inputData.mode,
|
|
422
415
|
revicedFootfall: revisedFootfall,
|
|
423
|
-
count:
|
|
416
|
+
count: tempAcc,
|
|
424
417
|
revisedDetail: formattedTaggingData,
|
|
425
418
|
status: 'raised',
|
|
426
419
|
createdByEmail: req?.user?.email,
|
|
427
420
|
createdByUserName: req?.user?.userName,
|
|
428
421
|
createdByRole: req?.user?.role,
|
|
422
|
+
createdAt: new Date(),
|
|
429
423
|
},
|
|
430
424
|
],
|
|
431
425
|
};
|