tango-app-api-analysis-traffic 3.0.0-alpha.51 → 3.0.0-alpha.54

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.51",
3
+ "version": "3.0.0-alpha.54",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -64,20 +64,29 @@ export async function addBills( req, res ) {
64
64
  let errorData=[];
65
65
  const openSearch = JSON.parse( process.env.OPENSEARCH );
66
66
  const inputData = req.body;
67
+ if ( req.user.role !== 'superadmin' && req.user.userType !== 'tango'&& ( inputData?.assignedStores?.length == 0 || !inputData?.assignedStores ) ) {
68
+ return res.sendError( 'access forbidden', 403 );
69
+ }
70
+
71
+ let filter = [];
72
+ if ( req.user.role !== 'superadmin' && req.user.userType !== 'tango' ) {
73
+ filter.push( { storeId: { $in: inputData?.assignedStores } } );
74
+ }
67
75
  for ( let i=0; i<inputData?.bills?.length; i++ ) {
76
+ filter = [
77
+ { clientId: { $eq: req.clientId } },
78
+ { status: { $eq: 'active' } },
79
+ {
80
+ $or: [
81
+ { 'storeId': inputData?.bills[i]?.storeCode },
82
+ { 'storeProfile.storeCode': inputData?.bills[i]?.storeCode },
83
+ ],
84
+ },
85
+ ];
68
86
  const query = [
69
87
  {
70
88
  $match: {
71
- $and: [
72
- { clientId: { $eq: req.clientId } },
73
- { status: { $eq: 'active' } },
74
- {
75
- $or: [
76
- { 'storeId': inputData?.bills[i]?.storeCode },
77
- { 'storeProfile.storeCode': inputData?.bills[i]?.storeCode },
78
- ],
79
- },
80
- ],
89
+ $and: filter,
81
90
  },
82
91
  },
83
92
  {
@@ -115,11 +124,12 @@ export async function addBills( req, res ) {
115
124
  let searchData=await getOpenSearchData( openSearch.nob, searchQuery );
116
125
  let nobDateIso =new Date( inputData?.bills[i]?.nobDate );
117
126
  nobDateIso.setUTCHours( 0, 0, 0, 0 );
127
+ const storeName = storeData[0]?.storeName;
118
128
  let inserData={
119
129
  clientId: req?.clientId,
120
130
  storeId: storeData[0]?.storeId,
121
131
  storeCode: storeData[0]?.storeCode,
122
- storeName: storeData[0]?.storeName,
132
+ storeName: storeName.toLowerCase(),
123
133
  nobDate: nobDateIso,
124
134
  nobCount: inputData?.bills[i]?.nobCount,
125
135
  dateString: inputData?.bills[i]?.nobDate,
@@ -185,6 +195,7 @@ export async function getNobData( req, res ) {
185
195
  const searchValue = escapeSpecialChars( inputData.searchValue );
186
196
  logger.info( { searchvalue: inputData.searchValue, searchValue: searchValue } );
187
197
  temp = {
198
+
188
199
  'must': filter,
189
200
  'should': [
190
201
  {
@@ -204,7 +215,7 @@ export async function getNobData( req, res ) {
204
215
  {
205
216
  'wildcard': {
206
217
  'storeName.keyword': {
207
- 'value': `${searchValue}*`,
218
+ 'value': `${searchValue.toLowerCase()}*`,
208
219
  },
209
220
  },
210
221
  },
@@ -313,7 +324,7 @@ export async function getNobData( req, res ) {
313
324
  footfallCount: temp[0]?.footfallCount || null,
314
325
  engagersCount: temp[0]?.engagersCount || null,
315
326
  potentialBuyers: temp[0]?.potentialBuyers || null,
316
- conversionRate: parseFloat( conversionCount.toFixed( 1 ) ),
327
+ conversionRate: conversionCount == null ? null :Math.round( conversionCount ),
317
328
 
318
329
  } );
319
330
  } else {
@@ -4,9 +4,18 @@ export const addBillsSchema = joi.object( {
4
4
 
5
5
  bills: joi.array().items(
6
6
  joi.object( {
7
- storeCode: joi.string().required(),
8
- nobDate: joi.string().required(),
9
- nobCount: joi.number().required(),
7
+ storeCode: joi.string().required().messages( {
8
+ 'string.empty': 'Please enter a valid Store ID',
9
+ 'any.required': 'Store ID is required',
10
+ } ),
11
+ nobDate: joi.string().required().messages( {
12
+ 'string.empty': 'Please enter a valid NOB Date',
13
+ 'any.required': 'NOB Date is required',
14
+ } ),
15
+ nobCount: joi.number().required().messages( {
16
+ 'string.empty': 'Please enter a valid NOB Count',
17
+ 'any.required': 'NOB Count is required',
18
+ } ),
10
19
  } ),
11
20
  ).required(),
12
21
 
@@ -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' ] } ), validate( addBillsValid ), roleVerification, clientValidations, addBills );
12
+ nobRouter.post( '/add-bills', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( addBillsValid ), roleVerification, clientValidations, getAssinedStore, addBills );
13
13
 
14
14
  nobRouter.post( '/get-nob-data', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( getNobDataValid ), clientValidations, getAssinedStore, getNobData );
15
15