tango-app-api-analysis-traffic 3.0.0-alpha.55 → 3.0.0-alpha.57

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.55",
3
+ "version": "3.0.0-alpha.57",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -169,6 +169,9 @@ export async function getNobData( req, res ) {
169
169
  }
170
170
 
171
171
  const footfallQuery={
172
+ '_source': {
173
+ 'exclude': [ 'storeName' ], // Specify the fields to exclude
174
+ },
172
175
  'query': {
173
176
  'bool': {
174
177
  'must': [
@@ -188,6 +191,7 @@ export async function getNobData( req, res ) {
188
191
 
189
192
  const getFootfall= await getOpenSearchData( openSearch.footfall, footfallQuery );
190
193
  const footfall = getFootfall?.body?.hits?.hits;
194
+ logger.info( { footfall: footfall, nobData: nobData } );
191
195
  let result=[];
192
196
  nobData.map( ( data ) => {
193
197
  let count = 0;
@@ -199,6 +203,7 @@ export async function getNobData( req, res ) {
199
203
  count = 1;
200
204
  temp =[
201
205
  {
206
+ storeName: item._source.store_name,
202
207
  footfallCount: item._source.footfall_count,
203
208
  engagersCount: item._source.engagers_count,
204
209
  potentialBuyers: item._source.potentialBuyers_count,
@@ -225,10 +230,11 @@ export async function getNobData( req, res ) {
225
230
  result.push( {
226
231
 
227
232
  ...data._source,
233
+ storeName: temp[0]?.storeName,
228
234
  footfallCount: temp[0]?.footfallCount || null,
229
235
  engagersCount: temp[0]?.engagersCount || null,
230
236
  potentialBuyers: temp[0]?.potentialBuyers || null,
231
- conversionRate: conversionCount == null ? null :Math.round( conversionCount ),
237
+ conversionRate: conversionCount == null ? null :`${Math.round( conversionCount )} %`,
232
238
 
233
239
  } );
234
240
  } else {
@@ -9,7 +9,7 @@ const nobRouter=express.Router();
9
9
  // store list
10
10
  nobRouter.get( '/store-list', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( storeListValid ), clientValidations, getAssinedStore, storeList );
11
11
 
12
- nobRouter.post( '/add-bills', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), bulkValidate( addBillsValid ), roleVerification, clientValidations, fieldValidation, getAssinedStore, addBills );
12
+ nobRouter.post( '/add-bills', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), bulkValidate( addBillsValid ), roleVerification, clientValidations, getAssinedStore, fieldValidation, addBills );
13
13
 
14
14
  nobRouter.post( '/get-nob-data', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( getNobDataValid ), clientValidations, getAssinedStore, getNobData );
15
15
 
@@ -43,17 +43,27 @@ export async function fieldValidation( req, res, next ) {
43
43
  if ( req.user.role !== 'superadmin' && req.user.userType !== 'tango' ) {
44
44
  filter.push( { storeId: { $in: inputData?.assignedStores } } );
45
45
  }
46
- for ( let i=0; i<inputData?.bills?.length; i++ ) {
47
- if ( inputData?.bills[i]?.storeCode == null ) {
48
- delete inputData?.bills[i];
46
+ const inputFilter = inputData?.bills.filter( ( item ) => ( item.storeCode !== null && item.nobDate !== null && item.nobCount !== null ) );
47
+ // Find duplicates
48
+ const seen = new Map();
49
+ logger.info( { inputFilter: inputFilter } );
50
+ for ( let i=0; i<inputFilter?.length&& inputFilter.length !== 0; i++ ) {
51
+ const key = `${inputFilter[i]?.storeCode}-${inputFilter[i]?.nobDate}`; // Combine `storeCode` and `nobDate` to create a unique key
52
+ logger.info( { key: key } );
53
+ if ( seen.has( key ) ) {
54
+ logger.info( { message: 'deupkilicare' } );
55
+ // duplicates.push( { ...item, originalIndex: index } );
56
+ return res.sendError( `Error in index ${i+1}: Dublicate record exist`, 403 );
57
+ } else {
58
+ seen.set( key, i );
49
59
  }
50
60
  filter = [
51
61
  { clientId: { $eq: req.clientId } },
52
62
  { status: { $eq: 'active' } },
53
63
  {
54
64
  $or: [
55
- { 'storeId': inputData?.bills[i]?.storeCode },
56
- { 'storeProfile.storeCode': inputData?.bills[i]?.storeCode },
65
+ { 'storeId': inputFilter[i]?.storeCode },
66
+ { 'storeProfile.storeCode': inputFilter[i]?.storeCode },
57
67
  ],
58
68
  },
59
69
  ];
@@ -88,7 +98,7 @@ export async function fieldValidation( req, res, next ) {
88
98
  },
89
99
  {
90
100
  'term': {
91
- 'nobDate': dayjs( inputData?.bills[i]?.nobDate ).format( 'YYYY-MM-DD' ),
101
+ 'nobDate': dayjs( inputFilter[i]?.nobDate ).format( 'YYYY-MM-DD' ),
92
102
  },
93
103
  },
94
104
  ],
@@ -100,7 +110,7 @@ export async function fieldValidation( req, res, next ) {
100
110
  return res.sendError( `Error in index ${i+1}: Access Forbidden.You are trying to re-upload/edit more than one time `, 403 );
101
111
  }
102
112
 
103
- let nobDateIso =new Date( inputData?.bills[i]?.nobDate );
113
+ let nobDateIso =new Date( inputFilter[i]?.nobDate );
104
114
  nobDateIso.setUTCHours( 0, 0, 0, 0 );
105
115
  const storeName = storeData[0]?.storeName;
106
116
  let inserData={
@@ -109,10 +119,10 @@ export async function fieldValidation( req, res, next ) {
109
119
  storeCode: storeData[0]?.storeCode,
110
120
  storeName: storeName.toLowerCase(),
111
121
  nobDate: nobDateIso,
112
- nobCount: inputData?.bills[i]?.nobCount,
113
- dateString: inputData?.bills[i]?.nobDate,
122
+ nobCount: inputFilter[i]?.nobCount,
123
+ dateString: inputFilter[i]?.nobDate,
114
124
  };
115
- const query ={ storeId: storeData[0]?.storeId, nobDate: inputData?.bills[i]?.nobDate };
125
+ const query ={ storeId: storeData[0]?.storeId, nobDate: inputFilter[i]?.nobDate };
116
126
 
117
127
  tempInserData.push( { data: inserData, query: query, searchData: searchData, isUpdated: ( searchData?.body?.hits?.hits?.length==0 || searchData?.body==undefined )? false:true } );
118
128
  }
@@ -126,6 +136,7 @@ export async function fieldValidation( req, res, next ) {
126
136
  }
127
137
  }
128
138
  }
139
+ return res.sendError( 'Bad Request', 400 );
129
140
  } catch ( error ) {
130
141
  logger.error( { error: error, message: req.body, function: 'nob-roleVerification' } );
131
142
  return res.sendError( error, 500 );