tango-app-api-analysis-traffic 3.8.7-vms.22 → 3.8.7-vms.24

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-analysis-traffic",
3
- "version": "3.8.7-vms.22",
3
+ "version": "3.8.7-vms.24",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "mongodb": "^6.8.0",
24
24
  "nodemon": "^3.1.4",
25
25
  "swagger-ui-express": "^5.0.1",
26
- "tango-api-schema": "^2.4.29",
26
+ "tango-api-schema": "^2.5.2",
27
27
  "tango-app-api-middleware": "^3.6.5",
28
28
  "winston": "^3.13.1",
29
29
  "winston-daily-rotate-file": "^5.0.0"
@@ -579,6 +579,7 @@ export async function footFallImages( req, res ) {
579
579
  let resultData = await LamdaServiceCall( LamdaURL, inputData );
580
580
  if ( resultData ) {
581
581
  // temp.length? temp[0].status = 'open': null;
582
+
582
583
  if ( resultData.status_code == '200' ) {
583
584
  return res.sendSuccess( { ...resultData, ticketStatus: temp?.length > 0 && ticketDetails? temp : null, config: req?.store?.footfallDirectoryConfigs } );
584
585
  } else {
@@ -1,25 +1,92 @@
1
1
  import { getOpenSearchCount, logger } from 'tango-app-api-middleware';
2
2
  import { deleteByQuery, getOpenSearchData } from 'tango-app-api-middleware/src/utils/openSearch.js';
3
- import { findOne } from '../services/clients.services.js';
3
+ import { aggregate, findOne } from '../services/clients.services.js';
4
4
 
5
5
  export async function getTaggingConfig( req, res, next ) {
6
6
  try {
7
7
  const inputData= req.query;
8
8
  const clientId = inputData.storeId.split( '-' )[0];
9
- const getData = await findOne( { clientId: clientId }, { footfallDirectoryConfigs: 1 } );
9
+ const configQuery = [
10
+ {
11
+ $match: {
12
+ clientId: clientId,
13
+ },
14
+ },
15
+
16
+ // Filter limitations based on effectiveFrom <= date
17
+ {
18
+ $addFields: {
19
+ matchedLimitation: {
20
+ $filter: {
21
+ input: '$footfallDirectoryConfigs.taggingLimitation',
22
+ as: 'item',
23
+ cond: { $lte: [ '$$item.effectiveFrom', inputData.dateString ] },
24
+ },
25
+ },
26
+ },
27
+ },
28
+
29
+ // Pick latest effective record
30
+ {
31
+ $addFields: {
32
+ effectiveLimitation: {
33
+ $arrayElemAt: [
34
+ {
35
+ $slice: [
36
+ {
37
+ $sortArray: {
38
+ input: '$matchedLimitation',
39
+ sortBy: { effectiveFrom: -1 },
40
+ },
41
+ },
42
+ 1,
43
+ ],
44
+ },
45
+ 0,
46
+ ],
47
+ },
48
+ },
49
+ },
50
+
51
+ // Remove originals before final merge
52
+ {
53
+ $project: {
54
+ 'config.taggingLimitation': 0,
55
+ 'matchedLimitation': 0,
56
+ },
57
+ },
58
+
59
+ // Attach effective limitation INSIDE config
60
+ {
61
+ $addFields: {
62
+ 'config.effectiveLimitation': '$effectiveLimitation',
63
+ },
64
+ },
65
+
66
+ // Remove temporary field
67
+ {
68
+ $project: {
69
+ footfallDirectoryConfigs: 1,
70
+ },
71
+ },
72
+ ];
73
+
10
74
 
75
+ const getData = await aggregate( configQuery );
11
76
  // Convert "taggingLimitation" array (if present) to "config" object with expected key-value pairs
12
77
  let config = {};
13
- if ( getData && Array.isArray( getData.taggingLimitation ) ) {
14
- for ( const item of getData.taggingLimitation ) {
78
+ if ( getData && getData?.length > 0 && Array.isArray( getData?.[0]?.footfallDirectoryConfigs?.taggingLimitation ) ) {
79
+ for ( const item of getData?.[0]?.footfallDirectoryConfigs?.taggingLimitation?.[0]?.values ) {
15
80
  if ( item && item.type && typeof item.value !== 'undefined' && item.unit ) {
16
81
  config[item.type] = `${item.value}${item.unit}`;
17
82
  }
18
83
  }
19
84
  }
20
- getData.config = config;
85
+ // getData[0].footfallDirectoryConfigs.taggingLimitation = [];
86
+ getData[0].footfallDirectoryConfigs.config = config;
21
87
 
22
- req.store = getData;
88
+ getData[0].footfallDirectoryConfigs.taggingLimitation = getData[0].footfallDirectoryConfigs.taggingLimitation?.[0]?.values;
89
+ req.store = getData[0];
23
90
  next();
24
91
  } catch ( error ) {
25
92
  logger.error( { error: error, message: req.body, function: 'traffic-revop-getTaggingConfig' } );