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

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.48",
3
+ "version": "3.0.0-alpha.49",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -227,7 +227,28 @@ export async function getNobData( req, res ) {
227
227
  const getNobData=await getOpenSearchData( openSearch.nob, nobQuery );
228
228
  const nobData = getNobData?.body?.hits?.hits;
229
229
  if ( !nobData ||nobData?.length == 0 ) {
230
- return res.sendError( 'No Data Found', 204 );
230
+ const initialQuery={
231
+ 'size': 1,
232
+ 'query': {
233
+ 'bool': {
234
+ 'must': [
235
+ {
236
+ 'term': {
237
+ 'clientId.keyword': req.clientId,
238
+ },
239
+ },
240
+ ],
241
+ },
242
+ },
243
+ };
244
+ const getInitialData=await getOpenSearchData( openSearch.nob, initialQuery );
245
+ const initialData = getInitialData?.body?.hits?.hits;
246
+ logger.info( { initialData: initialData, clientId: req.clientId } );
247
+ if ( initialData && initialData.length > 0 ) {
248
+ return res.sendError( 'No Data Found', 204 );
249
+ } else {
250
+ return res.sendSuccess( { initialInsert: false } );
251
+ }
231
252
  }
232
253
 
233
254
  const footfallQuery={
@@ -2,14 +2,14 @@ import express from 'express';
2
2
  import { accessVerification, getAssinedStore, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
3
  import { addBillsValid, getNobDataValid, storeListValid } from '../dtos/nob.dtos.js';
4
4
  import { addBills, getNobData, storeList } from '../controllers/nob.controllers.js';
5
- import { clientValidations } from '../validations/nob.validations.js';
5
+ import { clientValidations, roleVerification } from '../validations/nob.validations.js';
6
6
 
7
7
  const nobRouter=express.Router();
8
8
 
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 ), clientValidations, addBills );
12
+ nobRouter.post( '/add-bills', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( addBillsValid ), roleVerification, clientValidations, addBills );
13
13
 
14
14
  nobRouter.post( '/get-nob-data', isAllowedSessionHandler, accessVerification( { userType: [ 'client', 'tango' ] } ), validate( getNobDataValid ), clientValidations, getAssinedStore, getNobData );
15
15
 
@@ -13,3 +13,16 @@ export async function clientValidations( req, res, next ) {
13
13
  return res.sendError( err, 500 );
14
14
  }
15
15
  }
16
+
17
+ export async function roleVerification( req, res, next ) {
18
+ try {
19
+ if ( [ 'admin', 'superadmin' ].includes( req?.user?.role ) ) {
20
+ return next();
21
+ } else {
22
+ return res.sendError( 'access forbidden', 403 );
23
+ }
24
+ } catch ( error ) {
25
+ logger.error( { error: error, message: req.body, function: 'nob-roleVerification' } );
26
+ return res.sendError( error, 500 );
27
+ }
28
+ }