tango-app-api-analysis-traffic 3.0.0-alpha.46 → 3.0.0-alpha.48

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.0.0-alpha.46",
3
+ "version": "3.0.0-alpha.48",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -156,7 +156,7 @@ export async function getNobData( req, res ) {
156
156
  return res.sendError( 'No data found', 204 );
157
157
  }
158
158
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( new Date( inputData.toDate ) ) );
159
-
159
+ let temp ={};
160
160
  let filter = [
161
161
  {
162
162
  'terms': {
@@ -170,28 +170,47 @@ export async function getNobData( req, res ) {
170
170
  ];
171
171
  if ( req.user.role !== 'superadmin' && req.user.userType !== 'tango' ) {
172
172
  filter.push(
173
- req.user.userType !== 'tango',
173
+ {
174
+ 'terms': {
175
+ 'storeId.keyword': inputData?.assignedStores,
176
+ },
177
+ },
174
178
  );
175
179
  }
180
+ temp = {
181
+ 'must': filter,
182
+ };
176
183
 
177
184
  if ( inputData.searchValue && inputData.searchValue!== '' ) {
178
185
  const searchValue = escapeSpecialChars( inputData.searchValue );
179
186
  logger.info( { searchvalue: inputData.searchValue, searchValue: searchValue } );
180
- filter.push(
187
+ temp = {
188
+ 'must': filter,
189
+ 'should': [
181
190
  {
182
191
  'wildcard': {
183
192
  'storeId.keyword': {
184
193
  'value': `${searchValue}*`,
185
194
  },
195
+ },
196
+ },
197
+ {
198
+ 'wildcard': {
186
199
  'storeCode.keyword': {
187
200
  'value': `${searchValue}*`,
188
201
  },
202
+ },
203
+ },
204
+ {
205
+ 'wildcard': {
189
206
  'storeName.keyword': {
190
207
  'value': `${searchValue}*`,
191
208
  },
192
209
  },
193
210
  },
194
- );
211
+ ],
212
+ 'minimum_should_match': 1,
213
+ };
195
214
  }
196
215
  const getClient = await findOne( { clientId: req.clientId }, { featureConfigs: 1 } );
197
216
  const openSearch = JSON.parse( process.env.OPENSEARCH );
@@ -201,9 +220,7 @@ export async function getNobData( req, res ) {
201
220
  'from': skip,
202
221
  'size': limit,
203
222
  'query': {
204
- 'bool': {
205
- 'must': filter,
206
- },
223
+ 'bool': temp,
207
224
  },
208
225
  };
209
226
 
@@ -214,8 +231,6 @@ export async function getNobData( req, res ) {
214
231
  }
215
232
 
216
233
  const footfallQuery={
217
- // 'from': skip,
218
- // 'size': limit,
219
234
  'query': {
220
235
  'bool': {
221
236
  'must': [
@@ -255,13 +270,29 @@ export async function getNobData( req, res ) {
255
270
  }
256
271
  } );
257
272
 
273
+ let conversionCount;
274
+
258
275
  if ( count === 1 ) {
276
+ switch ( getClient?.featureConfigs?.conversionCalculation ) {
277
+ case 'footfall-count':
278
+ conversionCount = temp[0]?.footfallCount? ( data?._source?.nobCount/temp[0]?.footfallCount )*100 : null;
279
+ break;
280
+ case 'billable-entities':
281
+ conversionCount = temp[0]?.potentialBuyers? ( data?._source?.nobCount/temp[0]?.potentialBuyers )*100 : null;
282
+ break;
283
+ case 'engagers-count':
284
+ conversionCount = temp[0]?.engagersCount? ( data?._source?.nobCount/temp[0]?.engagersCount )*100 : null;
285
+ break;
286
+ default:
287
+ conversionCount = temp[0]?.engagersCount? ( data?._source?.nobCount/temp[0]?.engagersCount )*100 : null;
288
+ }
259
289
  result.push( {
260
290
 
261
291
  ...data._source,
262
292
  footfallCount: temp[0]?.footfallCount || null,
263
293
  engagersCount: temp[0]?.engagersCount || null,
264
294
  potentialBuyers: temp[0]?.potentialBuyers || null,
295
+ conversionRate: parseFloat( conversionCount.toFixed( 1 ) ),
265
296
 
266
297
  } );
267
298
  } else {
@@ -271,6 +302,7 @@ export async function getNobData( req, res ) {
271
302
  footfallCount: null,
272
303
  engagersCount: null,
273
304
  potentialBuyers: null,
305
+ conversionRate: null,
274
306
 
275
307
  } );
276
308
  }
@@ -279,18 +311,32 @@ export async function getNobData( req, res ) {
279
311
  const chunkedMappingData = await chunkArray( result, 10 );
280
312
  const promises = chunkedMappingData.map( async ( chunk ) => {
281
313
  const exportData = [];
282
- chunk.forEach( ( element ) => {
314
+
315
+
316
+ chunk.forEach( ( element, index ) => {
283
317
  exportData.push( {
284
318
  'Store Name': element.storeName,
285
319
  'Store Id': element.storeId,
286
- 'Date': element.nobDate,
287
- 'Footfall': element.footfallCount,
320
+ 'Date': dayjs( element.nobDate ).format( 'D MMM,YYYY' ),
288
321
  'NoB\'s Count': element.nobCount,
289
- 'Conversion Rate': `${( element.footfallCount/element.nobCount )*100}%`,
290
-
291
322
 
292
323
  } );
324
+ switch ( getClient?.featureConfigs?.conversionCalculation ) {
325
+ case 'footfall-count':
326
+ exportData[index]['Footfall'] = element.footfallCount;
327
+ break;
328
+ case 'billable-entities':
329
+ exportData[index]['Potential Buyers'] = element.potentialBuyers;
330
+ break;
331
+ case 'engagers-count':
332
+ exportData[index]['Engagers Count'] = element.engagersCount;
333
+ break;
334
+ default:
335
+ exportData[index]['Engagers Count'] = element.engagersCount;
336
+ }
337
+ element.conversionRate? exportData[index]['Conversion Rate'] = `${element.conversionRate} %` : exportData[index]['Conversion Rate'] =null;
293
338
  } );
339
+ logger.info( { exportData: exportData } );
294
340
  return exportData;
295
341
  } );
296
342
  const mappedArrays = await Promise.all( promises );