tango-app-api-analysis-traffic 3.3.1-alpha.5 → 3.3.1-alpha.7

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/app.js ADDED
@@ -0,0 +1,60 @@
1
+ import express from 'express';
2
+ import { analysisTrafficRouter } from './index.js';
3
+
4
+ import dotenv from 'dotenv';
5
+ import pkg from 'body-parser';
6
+ const { json, urlencoded } = pkg;
7
+ import { logger } from 'tango-app-api-middleware';
8
+ import { connectdb } from './config/database/database.js';
9
+ import responseMiddleware from './config/response/response.js';
10
+ import errorMiddleware from './config/response/error.js';
11
+ import cors from 'cors';
12
+ import fs from 'fs';
13
+ import path from 'path';
14
+ import { fileURLToPath } from 'url';
15
+
16
+ // Define __dirname for ES modules
17
+ const __filename = fileURLToPath( import.meta.url );
18
+ const __dirname = path.dirname( __filename );
19
+
20
+ const env=dotenv.config();
21
+
22
+ const app = express();
23
+ const PORT = process.env.PORT || 3000;
24
+ app.use( cors() );
25
+
26
+
27
+ if ( env.error ) {
28
+ logger.error( '.env not found' );
29
+ process.exit( 1 );
30
+ }
31
+
32
+ app.use( json( { limit: '500mb' } ) );
33
+ app.use(
34
+ urlencoded( {
35
+ extended: true,
36
+ } ),
37
+ );
38
+
39
+ app.use( responseMiddleware );
40
+ app.use( errorMiddleware );
41
+
42
+ app.use( '/trafficAnalysis', analysisTrafficRouter );
43
+ app.get( '/log', ( req, res ) => {
44
+ const logFilePath = path.join( __dirname, 'storage', 'logs', `error-${req.query.date}.log` );
45
+ console.log( logFilePath );
46
+ fs.readFile( logFilePath, 'utf8', ( err, data ) => {
47
+ if ( err ) {
48
+ console.error( 'File Read Error:', err );
49
+ return res.status( 500 ).send( `Error reading log file: ${err.message}` );
50
+ }
51
+
52
+
53
+ res.type( 'text/plain' ).send( data );
54
+ } );
55
+ } );
56
+
57
+ app.listen( PORT, () => {
58
+ console.log( `server is running on port= ${PORT} ` );
59
+ connectdb();
60
+ } );
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-analysis-traffic",
3
- "version": "3.3.1-alpha.5",
3
+ "version": "3.3.1-alpha.7",
4
4
  "description": "Traffic Analysis",
5
- "main": "index.js",
5
+ "main": "app.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node index.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node app.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -1070,6 +1070,8 @@ export const headerStoresV2 = async ( req, res ) => {
1070
1070
  { storeId: { $in: totalStores } },
1071
1071
  { storeId: { $in: unqueCityStores } },
1072
1072
  { storeId: { $in: unqueGroupStores } },
1073
+ { 'edge.firstFile': true },
1074
+ { status: { $eq: 'active' } },
1073
1075
  ],
1074
1076
  },
1075
1077
  },
@@ -1089,6 +1091,8 @@ export const headerStoresV2 = async ( req, res ) => {
1089
1091
  $and: [
1090
1092
  { storeId: { $in: totalStores } },
1091
1093
  { storeId: { $in: uniqueCityStores } },
1094
+ { 'edge.firstFile': true },
1095
+ { status: { $eq: 'active' } },
1092
1096
  ],
1093
1097
  },
1094
1098
  },
@@ -1108,6 +1112,8 @@ export const headerStoresV2 = async ( req, res ) => {
1108
1112
  $and: [
1109
1113
  { storeId: { $in: totalStores } },
1110
1114
  { storeId: { $in: uniqueclusterStores } },
1115
+ { 'edge.firstFile': true },
1116
+ { status: { $eq: 'active' } },
1111
1117
  ],
1112
1118
  },
1113
1119
  },
@@ -1126,6 +1132,8 @@ export const headerStoresV2 = async ( req, res ) => {
1126
1132
  $match: {
1127
1133
  $and: [
1128
1134
  { storeId: { $in: totalStores } },
1135
+ { 'edge.firstFile': true },
1136
+ { status: { $eq: 'active' } },
1129
1137
  ],
1130
1138
  },
1131
1139
  },
@@ -1360,6 +1368,7 @@ async function getAssignedAllStores( userClientId ) {
1360
1368
  $and: [
1361
1369
  { clientId: { $eq: userClientId } },
1362
1370
  { status: { $eq: 'active' } },
1371
+ { 'edge.firstFile': true },
1363
1372
  ],
1364
1373
  },
1365
1374
  },
@@ -1489,6 +1498,7 @@ async function getLocationStores( userClientId, cityList, req ) {
1489
1498
  if ( req.body.assignedStores&&req.body.assignedStores.length>0 ) {
1490
1499
  filter.push( { storeId: { $in: req.body.assignedStores } } );
1491
1500
  }
1501
+ filter.push( { 'edge.firstFile': true }, { status: { $eq: 'active' } } );
1492
1502
 
1493
1503
  let storeQuery = [
1494
1504
  {
@@ -8,10 +8,15 @@ export const addBillsSchema = joi.object( {
8
8
  'string.empty': 'Please enter a valid Store ID',
9
9
  'any.required': 'Store ID is required',
10
10
  } ).allow( null ),
11
- nobDate: joi.string().required().messages( {
12
- 'string.empty': 'Please enter a valid NOB Date',
13
- 'any.required': 'NOB Date is required',
14
- } ).allow( null ),
11
+ nobDate: joi.string()
12
+ .pattern( /^\d{4}-\d{2}-\d{2}$/ ) // Ensures format YYYY-MM-DD
13
+ .required()
14
+ .messages( {
15
+ 'string.pattern.base': 'NOB Date must be in YYYY-MM-DD format',
16
+ 'string.empty': 'Please enter a valid NOB Date',
17
+ 'any.required': 'NOB Date is required',
18
+ } )
19
+ .allow( null ),
15
20
  nobCount: joi.number().required().messages( {
16
21
  'string.empty': 'Please enter a valid NOB Count',
17
22
  'any.required': 'NOB Count is required',