tango-app-api-infra 3.8.1-beta.8 → 3.8.1-beta.9

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.8.1-beta.8",
3
+ "version": "3.8.1-beta.9",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -10,11 +10,12 @@ export async function createTicket( req, res ) {
10
10
  const getStoreName = await findOneStore( { storeId: inputData.storeId }, { storeName: 1, _id: 0 } );
11
11
  inputData.ticketId = 'TE_FDT_' + new Date().valueOf();
12
12
  inputData.clientId = inputData?.storeId?.split( '-' )[0];
13
- inputData.storeName =getStoreName?.storeName;
13
+ inputData.storeName = getStoreName?.storeName;
14
14
  inputData.createdAt = new Date();
15
15
  inputData.updatedAt = new Date();
16
- inputData.userName = req.user.userName;
17
- inputData.role = req.user.role;
16
+ inputData.userName = req?.user?.userName;
17
+ inputData.email = req?.user?.email;
18
+ inputData.role = req?.user?.role;
18
19
  inputData.status = 'open';
19
20
  if ( inputData.houseKeepingCount > 0 ) {
20
21
  inputData.houseKeepingStatus = 'pending';
@@ -67,7 +68,7 @@ async function bulkUpdateStatusToPending( indexName, inputData ) {
67
68
 
68
69
  // 3. Duplicate Images > data[]
69
70
  if ( inputData.duplicateCount > 0 ) {
70
- let updatedDuplicateImages =[];
71
+ let updatedDuplicateImages = [];
71
72
  for ( const dup of inputData.duplicateImages || [] ) {
72
73
  const id = `${inputData.storeId}_${inputData.dateString}_${dup.timeRange}_${dup.tempId}`;
73
74
  dup?.data?.map( ( item ) => {
@@ -184,13 +185,13 @@ export async function ticketList( req, res ) {
184
185
  const openSearch = JSON.parse( process.env.OPENSEARCH );
185
186
  const inputData = req.query;
186
187
  const limit = inputData.limit || 10;
187
- const offset= inputData.offset == 0? 0:( inputData.offset - 1 ) *limit || 0;
188
+ const offset = inputData.offset == 0 ? 0 : ( inputData.offset - 1 ) * limit || 0;
188
189
  const order = inputData?.sortOrder || -1;
189
190
 
190
191
  inputData.clientId = inputData.clientId.split( ',' ); // convert strig to array
191
192
 
192
193
 
193
- let filter= [
194
+ let filter = [
194
195
  {
195
196
  'range': {
196
197
  'dateString': {
@@ -200,17 +201,33 @@ export async function ticketList( req, res ) {
200
201
  },
201
202
  },
202
203
  },
203
- { terms: { 'clientId.keyword': Array.isArray( inputData.clientId ) ?
204
- inputData.clientId :
205
- inputData.clientId } },
204
+ {
205
+ terms: {
206
+ 'clientId.keyword': Array.isArray( inputData.clientId ) ?
207
+ inputData.clientId :
208
+ [ inputData.clientId ],
209
+ },
210
+ },
206
211
  ];
207
212
 
208
- let search ={
213
+ if ( inputData?.storeId ) {
214
+ filter.push(
215
+ {
216
+ terms: {
217
+ 'storeId.keyword': Array.isArray( inputData.storeId ) ?
218
+ inputData.storeId :
219
+ [ inputData.storeId ],
220
+ },
221
+ },
222
+ );
223
+ }
224
+
225
+ let search = {
209
226
  'must': filter,
210
227
  };
211
228
 
212
229
  if ( inputData.searchValue && inputData.searchValue !== '' ) {
213
- search ={
230
+ search = {
214
231
  'must': filter,
215
232
  'should': [
216
233
  {
@@ -247,12 +264,13 @@ export async function ticketList( req, res ) {
247
264
  };
248
265
  }
249
266
 
250
- let searchQuery={
267
+ let searchQuery = {
251
268
  '_source': [
252
269
  'storeName',
253
270
  'storeId',
254
271
  'ticketId',
255
272
  'createdAt',
273
+ 'updatedAt',
256
274
  'footfallCount',
257
275
  'duplicateCount',
258
276
  'employeeCount',
@@ -280,12 +298,13 @@ export async function ticketList( req, res ) {
280
298
  }
281
299
 
282
300
 
283
- searchQuery={
301
+ searchQuery = {
284
302
  '_source': [
285
303
  'storeName',
286
304
  'storeId',
287
305
  'ticketId',
288
306
  'createdAt',
307
+ 'updatedAt',
289
308
  'footfallCount',
290
309
  'duplicateCount',
291
310
  'employeeCount',
@@ -299,18 +318,19 @@ export async function ticketList( req, res ) {
299
318
  'bool': search,
300
319
  },
301
320
  'sort': [
302
- { [sortByValue]: { order: order === -1 ?'desc':'asc' } },
321
+ { [sortByValue]: { order: order === -1 ? 'desc' : 'asc' } },
303
322
  ],
304
323
  };
305
324
  }
306
325
 
307
- if ( inputData.isExport==true ) {
308
- searchQuery={
326
+ if ( inputData.isExport == true ) {
327
+ searchQuery = {
309
328
  '_source': [
310
329
  'storeName',
311
330
  'storeId',
312
331
  'ticketId',
313
332
  'createdAt',
333
+ 'updatedAt',
314
334
  'footfallCount',
315
335
  'duplicateCount',
316
336
  'employeeCount',
@@ -338,7 +358,7 @@ export async function ticketList( req, res ) {
338
358
  return res.sendError( 'No data found', 204 );
339
359
  }
340
360
 
341
- if ( inputData.isExport==true ) {
361
+ if ( inputData.isExport == true ) {
342
362
  const exportData = [];
343
363
  for ( const item of searchValue ) {
344
364
  exportData.push( {
@@ -350,7 +370,7 @@ export async function ticketList( req, res ) {
350
370
  'Duplicates': item._source.duplicateCount,
351
371
  'Employee/Staff': item._source.employeeCount,
352
372
  'HouseKeeping': item._source.houseKeepingCount,
353
- 'Revised Footfalls': item._source.footfallCount-( item._source.duplicateCount+item._source.employeeCount+item._source.houseKeepingCount ),
373
+ 'Revised Footfalls': item._source.footfallCount - ( item._source.duplicateCount + item._source.employeeCount + item._source.houseKeepingCount ),
354
374
  'Status': item._source.status,
355
375
  } );
356
376
  }
@@ -369,14 +389,17 @@ export async function getTickets( req, res ) {
369
389
  const openSearch = JSON.parse( process.env.OPENSEARCH );
370
390
  const inputData = req.query;
371
391
  const limit = inputData.limit;
372
- const skip= inputData.offset == 0? 0:( inputData.offset - 1 ) *limit || 0;
392
+ const skip = inputData.offset == 0 ? 0 : ( inputData.offset - 1 ) * limit || 0;
373
393
  inputData.storeId = inputData.storeId.split( ',' ); // convert strig to array
374
394
  logger.info( { inputData: inputData, limit: limit, skip: skip } );
375
395
  let source = [ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'employeeCount', 'houseKeepingCount', 'duplicateCount', 'comments', 'employee', 'houseKeeping', 'duplicateImages', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ];
376
- let filter =[
377
- { terms: { 'storeId.keyword': Array.isArray( inputData.storeId ) ?
378
- inputData.storeId :
379
- inputData.storeId },
396
+ let filter = [
397
+ {
398
+ terms: {
399
+ 'storeId.keyword': Array.isArray( inputData.storeId ) ?
400
+ inputData.storeId :
401
+ inputData.storeId,
402
+ },
380
403
  },
381
404
  {
382
405
  range: {
@@ -405,32 +428,32 @@ export async function getTickets( req, res ) {
405
428
  field: inputData.revopsType,
406
429
  },
407
430
  } );
408
- inputData.revopsType === 'employee'?
409
- filter.push( {
410
- range: {
411
- employeeCount: {
412
- gt: 0,
413
- },
414
- },
415
- } ) :
416
- inputData.revopsType === 'housekeeping'?
417
- filter.push( {
418
- range: {
419
- housekeepingCount: {
420
- gt: 0,
421
- },
422
- },
423
- } ):
424
- filter.push( {
425
- range: {
426
- duplicateCount: {
427
- gt: 0,
431
+ inputData.revopsType === 'employee' ?
432
+ filter.push( {
433
+ range: {
434
+ employeeCount: {
435
+ gt: 0,
436
+ },
428
437
  },
429
- },
430
- } );
431
- source= inputData.revopsType == 'employee' ?[ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'employeeCount', 'comments', 'employee', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ]:
432
- inputData.revopsType == 'houseKeeping' ?[ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'houseKeepingCount', 'comments', 'houseKeeping', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ]:
433
- inputData.revopsType == 'duplicateImages' ?[ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'duplicateCount', 'comments', 'duplicateImages', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ] : [];
438
+ } ) :
439
+ inputData.revopsType === 'housekeeping' ?
440
+ filter.push( {
441
+ range: {
442
+ housekeepingCount: {
443
+ gt: 0,
444
+ },
445
+ },
446
+ } ) :
447
+ filter.push( {
448
+ range: {
449
+ duplicateCount: {
450
+ gt: 0,
451
+ },
452
+ },
453
+ } );
454
+ source = inputData.revopsType == 'employee' ? [ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'employeeCount', 'comments', 'employee', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ] :
455
+ inputData.revopsType == 'houseKeeping' ? [ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'houseKeepingCount', 'comments', 'houseKeeping', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ] :
456
+ inputData.revopsType == 'duplicateImages' ? [ 'storeId', 'dateString', 'ticketName', 'footfallCount', 'duplicateCount', 'comments', 'duplicateImages', 'ticketId', 'clientId', 'storeName', 'createdAt', 'updatedAt', 'userName', 'role', 'status', 'employeeStatus', 'houseKeepingStatus', 'duplicateStatus' ] : [];
434
457
  }
435
458
 
436
459
  if ( inputData.action ) {
@@ -459,7 +482,7 @@ export async function getTickets( req, res ) {
459
482
  }
460
483
  let getRevCount = {};
461
484
  if ( inputData.revopsType ) {
462
- getRevCount= {
485
+ getRevCount = {
463
486
  size: 0,
464
487
  query: {
465
488
  bool: {
@@ -469,13 +492,13 @@ export async function getTickets( req, res ) {
469
492
  aggs: {
470
493
  totalCount: {
471
494
  sum: {
472
- field: inputData.revopsType == 'employee'? 'employeeCount':inputData.revopsType == 'houseKeeping'?'houseKeepingCount': 'duplicateCount',
495
+ field: inputData.revopsType == 'employee' ? 'employeeCount' : inputData.revopsType == 'houseKeeping' ? 'houseKeepingCount' : 'duplicateCount',
473
496
  },
474
497
  },
475
498
  },
476
499
  };
477
500
  }
478
- const getCount= {
501
+ const getCount = {
479
502
  query: {
480
503
  bool: {
481
504
  filter: filter,
@@ -485,10 +508,10 @@ export async function getTickets( req, res ) {
485
508
 
486
509
 
487
510
  const geteDataCount = await getOpenSearchCount( openSearch.footfallDirectory, getCount );
488
- const geteRevDataCount = inputData?.revopsType? await getOpenSearchData( openSearch.footfallDirectory, getRevCount ) : null;
489
- const revCount = inputData?.revopsType? geteRevDataCount?.body?.aggregations?.totalCount?.value: 0;
511
+ const geteRevDataCount = inputData?.revopsType ? await getOpenSearchData( openSearch.footfallDirectory, getRevCount ) : null;
512
+ const revCount = inputData?.revopsType ? geteRevDataCount?.body?.aggregations?.totalCount?.value : 0;
490
513
  const count = geteDataCount?.body?.count;
491
- if ( !geteDataCount || count==0 ) {
514
+ if ( !geteDataCount || count == 0 ) {
492
515
  return res.sendError( 'No data found', 204 );
493
516
  }
494
517
 
@@ -519,7 +542,7 @@ export async function getTickets( req, res ) {
519
542
  logger.info( { response: response, body: getData?.body, getData: getData, geteDataCount: geteDataCount } );
520
543
 
521
544
 
522
- if ( inputData.isExport=== true ) {
545
+ if ( inputData.isExport === true ) {
523
546
  const temp = [];
524
547
  for ( const item of response ) {
525
548
  temp.push( {
@@ -531,7 +554,7 @@ export async function getTickets( req, res ) {
531
554
  'Duplicates': item.duplicateCount,
532
555
  'Employee/Staff': item.employeeCount,
533
556
  'HouseKeeping': item.houseKeepingCount,
534
- 'Revised Footfalls': item.footfallCount-( item.duplicateCount+item.employeeCount+item.houseKeepingCount ),
557
+ 'Revised Footfalls': item.footfallCount - ( item.duplicateCount + item.employeeCount + item.houseKeepingCount ),
535
558
  'Status': item.status,
536
559
  } );
537
560
  }
@@ -539,7 +562,7 @@ export async function getTickets( req, res ) {
539
562
  return;
540
563
  }
541
564
 
542
- return res.sendSuccess( { result: inputData.revopsType? response: response, count: count, revopCount: revCount } );
565
+ return res.sendSuccess( { result: inputData.revopsType ? response : response, count: count, revopCount: revCount } );
543
566
  } catch ( error ) {
544
567
  const err = error.message || 'Internal Server Error';
545
568
  logger.error( { error: error, messgage: req.query } );
@@ -567,7 +590,7 @@ export async function updateStatus( req, res ) {
567
590
  { doc: { duplicateImage: duplicate.duplicateImage } },
568
591
  );
569
592
  duplicate?.data?.map( ( item ) => {
570
- item.isChecked == true? tempId.push( item.tempId ) : null;
593
+ item.isChecked == true ? tempId.push( item.tempId ) : null;
571
594
  bulkBody.push(
572
595
  { update: { _index: openSearch.revop, _id: `${storeId}_${dateString}_${item.timeRange}_${item.tempId}` } },
573
596
  { doc: { isChecked: item.isChecked } },
@@ -575,18 +598,18 @@ export async function updateStatus( req, res ) {
575
598
  } );
576
599
  }
577
600
  for ( let employee of inputData.employee ) {
578
- employee.isChecked == true? tempId.push( employee.tempId ) : null;
579
- bulkBody.push(
580
- { update: { _index: openSearch.revop, _id: `${storeId}_${dateString}_${employee.timeRange}_${employee.tempId}` } },
581
- { doc: { isChecked: employee.isChecked } },
582
- );
601
+ employee.isChecked == true ? tempId.push( employee.tempId ) : null;
602
+ bulkBody.push(
603
+ { update: { _index: openSearch.revop, _id: `${storeId}_${dateString}_${employee.timeRange}_${employee.tempId}` } },
604
+ { doc: { isChecked: employee.isChecked } },
605
+ );
583
606
  }
584
607
  for ( let houseKeeping of inputData.houseKeeping ) {
585
- houseKeeping.isChecked == true? tempId.push( houseKeeping.tempId ) : null;
586
- bulkBody.push(
587
- { update: { _index: openSearch.revop, _id: `${storeId}_${dateString}_${houseKeeping.timeRange}_${houseKeeping.tempId}` } },
588
- { doc: { isChecked: houseKeeping.isChecked } },
589
- );
608
+ houseKeeping.isChecked == true ? tempId.push( houseKeeping.tempId ) : null;
609
+ bulkBody.push(
610
+ { update: { _index: openSearch.revop, _id: `${storeId}_${dateString}_${houseKeeping.timeRange}_${houseKeeping.tempId}` } },
611
+ { doc: { isChecked: houseKeeping.isChecked } },
612
+ );
590
613
  }
591
614
  // if ( inputData.status == 'closed' ) {
592
615
  // const isSendMessge = await sendSqsMessage( inputData, tempId );
@@ -637,7 +660,7 @@ export async function getTaggedStores( req, res ) {
637
660
  const openSearch = JSON.parse( process.env.OPENSEARCH );
638
661
  const inputData = req.query;
639
662
  logger.info( { inputData: inputData } );
640
- let filter= [
663
+ let filter = [
641
664
  {
642
665
  term: { 'clientId.keyword': inputData.clientId },
643
666
  },
@@ -71,6 +71,12 @@ export const footfallDirectoryDocs = {
71
71
  scema: j2s( ticketListSchema ).swagger,
72
72
  required: true,
73
73
  },
74
+ {
75
+ in: 'query',
76
+ name: 'storeId',
77
+ scema: j2s( ticketListSchema ).swagger,
78
+ required: false,
79
+ },
74
80
  {
75
81
  in: 'query',
76
82
  name: 'fromDate',
@@ -121,6 +121,7 @@ export const ticketSummaryValid = {
121
121
 
122
122
  export const ticketListSchema = Joi.object().keys( {
123
123
  clientId: Joi.string().required(),
124
+ storeId: Joi.string().optional(),
124
125
  searchValue: Joi.string().optional().allow( '' ),
125
126
  limit: Joi.number().optional(),
126
127
  offset: Joi.number().optional(),