tango-app-api-analysis-traffic 3.0.0-alpha.43 → 3.0.0-alpha.45

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.43",
3
+ "version": "3.0.0-alpha.45",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -61,6 +61,7 @@ export async function storeList( req, res ) {
61
61
  export async function addBills( req, res ) {
62
62
  try {
63
63
  let resData=[];
64
+ let errorData=[];
64
65
  const openSearch = JSON.parse( process.env.OPENSEARCH );
65
66
  const inputData = req.body;
66
67
  for ( let i=0; i<inputData?.bills?.length; i++ ) {
@@ -68,21 +69,29 @@ export async function addBills( req, res ) {
68
69
  {
69
70
  $match: {
70
71
  $and: [
71
- { clientId: { $eq: req.user.clientId } },
72
+ { clientId: { $eq: req.clientId } },
72
73
  { status: { $eq: 'active' } },
73
74
  {
74
75
  $or: [
75
- { 'storeId': inputData?.bills[i]?.storeId },
76
- { 'storeProfile.storeCode': inputData?.bills[i]?.storeId },
76
+ { 'storeId': inputData?.bills[i]?.storeCode },
77
+ { 'storeProfile.storeCode': inputData?.bills[i]?.storeCode },
77
78
  ],
78
79
  },
79
80
  ],
80
81
  },
81
82
  },
83
+ {
84
+ $project: {
85
+ storeId: 1,
86
+ storeName: 1,
87
+ storeCode: '$storeProfile.storeCode',
88
+
89
+ },
90
+ },
82
91
  ];
83
92
  let storeData= await aggregateStore( query );
84
93
  if ( storeData?.length ==0 ) {
85
- resData.push( { code: 400, storeId: inputData?.bills[i]?.storeId, message: 'Store code is not mapped with tango' } );
94
+ errorData.push( { code: 400, storeId: inputData?.bills[i]?.storeId, message: 'Store code is not mapped with tango' } );
86
95
  } else {
87
96
  let searchQuery={
88
97
  'size': 1,
@@ -107,10 +116,10 @@ export async function addBills( req, res ) {
107
116
  let nobDateIso =new Date( inputData?.bills[i]?.nobDate );
108
117
  nobDateIso.setUTCHours( 0, 0, 0, 0 );
109
118
  let inserData={
110
- clientId: req?.user?.clientId,
119
+ clientId: req?.clientId,
111
120
  storeId: storeData[0]?.storeId,
112
- storeCode: storeData[0]?.storeProfile?.storeCode,
113
- storeName: inputData?.bills[i]?.storeName,
121
+ storeCode: storeData[0]?.storeCode,
122
+ storeName: storeData[0]?.storeName,
114
123
  nobDate: nobDateIso,
115
124
  nobCount: inputData?.bills[i]?.nobCount,
116
125
  dateString: inputData?.bills[i]?.nobDate,
@@ -119,18 +128,20 @@ export async function addBills( req, res ) {
119
128
  const query ={ storeId: storeData[0]?.storeId, nobDate: inputData?.bills[i]?.nobDate };
120
129
  await updateOneNobBilling( query, inserData );
121
130
  const getData = await findOneNobBilling( query, { _id: 0 } );
122
- logger.info( { searchData: searchData } );
123
131
  if ( searchData?.body?.hits?.hits?.length==0 || searchData?.body==undefined ) {
124
- logger.info( { getData: getData } );
125
132
  await insertOpenSearchData( openSearch.nob, getData );
126
- resData.push( { code: 200, tangoCode: getData.storeId, storeId: inputData?.bills[i]?.storeId, message: 'Data Inserted Successfully' } );
133
+ resData.push( { code: 200, tangoCode: getData.storeId, storeId: inputData?.bills[i]?.storeCode, message: 'Data Inserted Successfully' } );
127
134
  } else {
128
135
  await updateOpenSearchData( openSearch.nob, searchData.body.hits.hits[0]._id, { doc: getData } );
129
- resData.push( { code: 200, tangoCode: storeData.id, storeId: inputData?.bills[i]?.storeId, message: 'Data Updated Successfully' } );
136
+ resData.push( { code: 200, tangoCode: storeData[0]?.storeId, storeId: inputData?.bills[i]?.storeCode, message: 'Data Updated Successfully' } );
130
137
  }
131
138
  }
132
139
  }
133
- return res.sendSuccess( { result: resData } );
140
+ if ( errorData.length > 0 && resData.length == 0 ) {
141
+ return res.sendError( 'Store code is not mapped with tango', 400 );
142
+ }
143
+ logger.info( { resData: resData, errorData: errorData, function: 'nob-addbills' } );
144
+ return res.sendSuccess( 'Data has been inserted successfully' );
134
145
  } catch ( error ) {
135
146
  const err= error.message || 'Internal Server Error';
136
147
  logger.error( { error: error, message: req.body, function: 'nob-addBills' } );
@@ -172,6 +183,12 @@ export async function getNobData( req, res ) {
172
183
  'storeId.keyword': {
173
184
  'value': `${searchValue}*`,
174
185
  },
186
+ 'storeCode.keyword': {
187
+ 'value': `${searchValue}*`,
188
+ },
189
+ 'storeName.keyword': {
190
+ 'value': `${searchValue}*`,
191
+ },
175
192
  },
176
193
  },
177
194
  );
@@ -4,9 +4,7 @@ export const addBillsSchema = joi.object( {
4
4
 
5
5
  bills: joi.array().items(
6
6
  joi.object( {
7
- storeId: joi.string().required(),
8
7
  storeCode: joi.string().required(),
9
- storeName: joi.string().required(),
10
8
  nobDate: joi.string().required(),
11
9
  nobCount: joi.number().required(),
12
10
  } ),
@@ -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 ), addBills );
12
+ nobRouter.post( '/add-bills', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( addBillsValid ), clientValidations, addBills );
13
13
 
14
14
  nobRouter.post( '/get-nob-data', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( getNobDataValid ), clientValidations, getAssinedStore, getNobData );
15
15