tango-app-api-client 3.3.3-beta.10 → 3.3.3-beta.12

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,40 @@
1
+ import express from 'express';
2
+ import { clientRouter } from './index.js';
3
+
4
+ import dotenv from 'dotenv';
5
+ import { logger } from 'tango-app-api-middleware';
6
+ import { connectdb } from './config/database/database.js';
7
+ import responseMiddleware from './config/response/response.js';
8
+ import errorMiddleware from './config/response/error.js';
9
+ import pkg from 'body-parser';
10
+ import { swaggerConfig } from './config/swagger/swagger.js';
11
+ import swagger from 'swagger-ui-express';
12
+
13
+ const { json, urlencoded } = pkg;
14
+ const env=dotenv.config();
15
+
16
+ const app = express();
17
+ const PORT = process.env.PORT || 3000;
18
+
19
+
20
+ app.use( json( { limit: '500mb' } ) );
21
+ app.use(
22
+ urlencoded( {
23
+ extended: true,
24
+ } ),
25
+ );
26
+ app.use( responseMiddleware );
27
+ app.use( errorMiddleware );
28
+
29
+ if ( env.error ) {
30
+ logger.error( '.env not found' );
31
+ process.exit( 1 );
32
+ }
33
+ app.use( '/api-docs', swagger.serve, swagger.setup( swaggerConfig ) );
34
+
35
+ app.use( '/v3/client', clientRouter );
36
+
37
+ app.listen( PORT, () => {
38
+ logger.info( `server is running on port= ${PORT} ` );
39
+ connectdb();
40
+ } );
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "tango-app-api-client",
3
- "version": "3.3.3-beta.10",
4
- "description": "client",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node index.js\""
9
- },
10
- "engines": {
11
- "node": ">=18.10.0"
12
- },
13
- "author": "praveenraj",
14
- "license": "ISC",
15
- "dependencies": {
16
- "aws-sdk": "^2.1560.0",
17
- "cors": "^2.8.5",
18
- "dotenv": "^16.4.4",
19
- "express": "^4.18.2",
20
- "express-fileupload": "^1.4.3",
21
- "handlebars": "^4.7.8",
22
- "joi": "^17.12.1",
23
- "joi-to-swagger": "^6.2.0",
24
- "lodash": "^4.17.21",
25
- "mongodb": "^6.7.0",
26
- "nodemon": "^3.0.3",
27
- "npm": "^10.9.1",
28
- "swagger-ui-express": "^5.0.0",
29
- "tango-api-schema": "^2.2.59",
30
- "tango-app-api-middleware": "^3.1.60",
31
- "winston": "^3.11.0",
32
- "winston-daily-rotate-file": "^5.0.0"
33
- },
34
- "devDependencies": {
35
- "eslint": "^8.56.0",
36
- "eslint-config-google": "^0.14.0",
37
- "eslint-config-semistandard": "^17.0.0",
38
- "eslint-config-standard": "^17.1.0",
39
- "eslint-plugin-import": "^2.29.1",
40
- "eslint-plugin-promise": "^6.1.1"
41
- }
42
- }
1
+ {
2
+ "name": "tango-app-api-client",
3
+ "version": "3.3.3-beta.12",
4
+ "description": "client",
5
+ "main": "app.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "nodemon --exec \"eslint --fix . && node app.js\""
9
+ },
10
+ "engines": {
11
+ "node": ">=18.10.0"
12
+ },
13
+ "author": "praveenraj",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "aws-sdk": "^2.1560.0",
17
+ "cors": "^2.8.5",
18
+ "dotenv": "^16.4.4",
19
+ "express": "^4.18.2",
20
+ "express-fileupload": "^1.4.3",
21
+ "handlebars": "^4.7.8",
22
+ "joi": "^17.12.1",
23
+ "joi-to-swagger": "^6.2.0",
24
+ "lodash": "^4.17.21",
25
+ "mongodb": "^6.7.0",
26
+ "nodemon": "^3.0.3",
27
+ "npm": "^10.9.1",
28
+ "swagger-ui-express": "^5.0.0",
29
+ "tango-api-schema": "^2.2.59",
30
+ "tango-app-api-middleware": "^3.1.60",
31
+ "winston": "^3.11.0",
32
+ "winston-daily-rotate-file": "^5.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "eslint": "^8.56.0",
36
+ "eslint-config-google": "^0.14.0",
37
+ "eslint-config-semistandard": "^17.0.0",
38
+ "eslint-config-standard": "^17.1.0",
39
+ "eslint-plugin-import": "^2.29.1",
40
+ "eslint-plugin-promise": "^6.1.1"
41
+ }
42
+ }
@@ -700,33 +700,40 @@ export async function updateBrandInfo( req, res ) {
700
700
  updateKeys.push( camelCaseToWords( element ) );
701
701
  } );
702
702
  }
703
+ const getPreCientInfo = await findOneClient( { clientId: req.params.id }, { _id: 0, registeredCompanyName: '$profileDetails.registeredCompanyName', industry: '$profileDetails.industry', clientType: '$profileDetails.clientType',
704
+ registeredAddress: '$profileDetails.registeredAddress', headQuarters: '$profileDetails.headQuarters', website: '$profileDetails.website', status: 1, averageTransactionValue: 1 } );
703
705
 
704
- const user = await getUserNameEmailById( req.userId );
705
706
 
707
+ const updateAck = await brandInfoUpdate( {
708
+ clientId: req.params?.id, registeredCompanyName: req.body?.registeredCompanyName, industry: req.body?.industry,
709
+ clientType: req.body?.clientType, registeredAddress: req.body?.registeredAddress, headQuarters: req.body?.headQuarters,
710
+ website: req.body?.website, status: req.body?.status, logo: req.files?.logo ? `brandLogo.${req.files.logo.name.split( '.' )[1]}` : undefined, averageTransactionValue: req.body?.averageTransactionValue,
711
+ } );
712
+ const getPosCientInfo = await findOneClient( { clientId: req.params.id }, { _id: 0, registeredCompanyName: '$profileDetails.registeredCompanyName', industry: '$profileDetails.industry', clientType: '$profileDetails.clientType',
713
+ registeredAddress: '$profileDetails.registeredAddress', headQuarters: '$profileDetails.headQuarters', website: '$profileDetails.website', status: 1, averageTransactionValue: 1 } );
706
714
 
707
715
  const logObj = {
708
716
  clientId: req.params?.id,
709
- userName: user?.userName,
710
- email: user?.email,
717
+ userName: req?.user?.userName,
718
+ email: req?.user?.email,
711
719
  date: new Date(),
712
720
  logType: 'brandDetails',
713
721
  logSubType: 'brandInfo',
714
722
  changes: updateKeys,
715
723
  eventType: 'update',
716
724
  showTo: [ 'client', 'tango' ],
725
+ previous: getPreCientInfo,
726
+ current: getPosCientInfo,
717
727
  };
718
-
728
+ logger.info( { previous: getPreCientInfo,
729
+ current: getPosCientInfo, logObj: logObj } );
719
730
  if ( updateKeys.length ) {
720
- await insertOpenSearchData( openSearch.activityLog, logObj );
731
+ logger.info( { updateKeys: updateKeys } );
732
+ const a =await insertOpenSearchData( openSearch.activityLog, logObj );
733
+ logger.info( { a: a } );
721
734
  }
722
735
 
723
736
 
724
- const updateAck = await brandInfoUpdate( {
725
- clientId: req.params?.id, registeredCompanyName: req.body?.registeredCompanyName, industry: req.body?.industry,
726
- clientType: req.body?.clientType, registeredAddress: req.body?.registeredAddress, headQuarters: req.body?.headQuarters,
727
- website: req.body?.website, status: req.body?.status, logo: req.files?.logo ? `brandLogo.${req.files.logo.name.split( '.' )[1]}` : undefined, averageTransactionValue: req.body?.averageTransactionValue,
728
- } );
729
-
730
737
  if ( req.body?.status === 'active' ) {
731
738
  await updateManyStore( { clientId: req.params?.id }, { status: 'active' } );
732
739
  await updateManyUser( { clientId: req.params?.id }, { isActive: true } );
@@ -878,7 +885,7 @@ export async function updateSignatoryDetails( req, res ) {
878
885
  export async function updateTicketConfiguration( req, res ) {
879
886
  try {
880
887
  const openSearch = JSON.parse( process.env.OPENSEARCH );
881
- let findClient = await findOneClient({clientId:req.params?.id})
888
+ let findClient = await findOneClient( { clientId: req.params?.id } );
882
889
  const updateAck = await ticketConfigurationUpdate( {
883
890
  clientId: req.params?.id, MinFilesCount: req.body?.MinFilesCount, accuracyPercentage: req.body?.accuracyPercentage, downTimeType: req.body?.downTimeType,
884
891
  infraDownTime: req.body?.infraDownTime, installationReAssign: req.body?.installationReAssign, isRcaTicketAssign: req.body?.isRcaTicketAssign,
@@ -894,7 +901,7 @@ export async function updateTicketConfiguration( req, res ) {
894
901
  }
895
902
 
896
903
  const user = await getUserNameEmailById( req.userId );
897
- let updatedClient = await findOneClient({clientId:req.params?.id})
904
+ let updatedClient = await findOneClient( { clientId: req.params?.id } );
898
905
 
899
906
  const logObj = {
900
907
  clientId: req.params?.id,
@@ -906,8 +913,8 @@ export async function updateTicketConfiguration( req, res ) {
906
913
  changes: updateKeys,
907
914
  eventType: 'update',
908
915
  showTo: [ 'tango' ],
909
- current:updatedClient.ticketConfigs,
910
- previous:findClient.ticketConfigs
916
+ current: updatedClient.ticketConfigs,
917
+ previous: findClient.ticketConfigs,
911
918
  };
912
919
 
913
920
  if ( updateKeys.length ) {
@@ -927,6 +934,7 @@ export async function updateFeatureConfiguration( req, res ) {
927
934
  try {
928
935
  const openSearch = JSON.parse( process.env.OPENSEARCH );
929
936
  const url = JSON.parse( process.env.URL );
937
+ const previousData = await findOneClient( { clientId: req.params?.id }, { featureConfigs: 1 } );
930
938
  const inputData = req.body;
931
939
  if ( inputData?.bouncedLimitValue ) {
932
940
  inputData.missedOpportunityFromValue = inputData?.bouncedLimitValue;
@@ -936,11 +944,12 @@ export async function updateFeatureConfiguration( req, res ) {
936
944
  inputData.missedOpportunityToValue = inputData?.conversionValue;
937
945
  }
938
946
  const updateAck = await featureConfigurationUpdate( { clientId: req.params?.id }, inputData );
939
-
947
+ const postData = await findOneClient( { clientId: req.params?.id }, { featureConfigs: 1 } );
940
948
  let updateKeys = [];
941
949
 
942
950
  if ( Object.keys( inputData ).length > 0 ) {
943
951
  Object.keys( inputData ).forEach( ( element ) => {
952
+ element === 'billableCalculation'? 'potentialCalculation': element;
944
953
  updateKeys.push( camelCaseToWords( element ) );
945
954
  } );
946
955
  }
@@ -998,10 +1007,12 @@ export async function updateFeatureConfiguration( req, res ) {
998
1007
  email: user?.email,
999
1008
  date: new Date(),
1000
1009
  logType: 'configuration',
1001
- logSubType: 'featureConfig',
1010
+ logSubType: inputData.includes['isExcludedArea', 'isPasserByData', 'isNormalized', 'isbillingDisabled', 'isCameraDisabled', 'isFootfallDirectory', 'isNOB', 'isNewTraffic', 'isTrax', 'isNewZone', 'isNewReports', 'isNewDashboard', 'streamBy']? 'dashboardConfig': 'featureConfig',
1002
1011
  changes: updateKeys,
1003
1012
  eventType: 'update',
1004
1013
  showTo: [ 'client', 'tango' ],
1014
+ pervious: previousData,
1015
+ current: postData,
1005
1016
  };
1006
1017
  if ( updateKeys.length ) {
1007
1018
  await insertOpenSearchData( openSearch.activityLog, logObj );
@@ -1020,6 +1031,7 @@ export async function updateFeatureConfiguration( req, res ) {
1020
1031
  export async function domainDetailsConfiguration( req, res ) {
1021
1032
  try {
1022
1033
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1034
+ const getPreData = await findOneClient( { clientId: req.params?.id }, { domainName: '$domainConfig.ssoLogin.domainName', TwoFactorAuthentication: '$domainConfig.ssoLogin.isEnable', ipWhitelist: '$domainConfig.ipWhitelisting.enableWhitelisting', WhitelistesIps: '$domainConfig.ipWhitelisting.allowedIps', enableOtp: '$domainConfig.enableOtp' } );
1023
1035
  const updateAck = await domainDetailsConfigurationUpdate( {
1024
1036
  clientId: req.params?.id, domainName: req.body?.domainName, isEnable: req.body?.isEnable,
1025
1037
  enableWhitelisting: req.body?.enableWhitelisting, allowedIps: req.body?.allowedIps, enableOtp: req.body?.enableOtp,
@@ -1034,19 +1046,20 @@ export async function domainDetailsConfiguration( req, res ) {
1034
1046
  } );
1035
1047
  }
1036
1048
 
1037
- const user = await getUserNameEmailById( req.userId );
1038
-
1049
+ const getPostData = await findOneClient( { clientId: req.params?.id }, { domainName: '$domainConfig.ssoLogin.domainName', TwoFactorAuthentication: '$domainConfig.enableOtp', ipWhitelist: '$domainConfig.ipWhitelisting.enableWhitelisting', WhitelistesIps: '$domainConfig.ipWhitelisting.allowedIps', isEnable: '$domainConfig.ssoLogin.isEnable' } );
1039
1050
 
1040
1051
  const logObj = {
1041
1052
  clientId: req.params?.id,
1042
- userName: user?.userName,
1043
- email: user?.email,
1053
+ userName: req?.user?.userName,
1054
+ email: req?.user?.email,
1044
1055
  date: new Date(),
1045
1056
  logType: 'configuration',
1046
1057
  logSubType: 'domainDetails',
1047
1058
  changes: updateKeys,
1048
1059
  eventType: 'update',
1049
1060
  showTo: [ 'client', 'tango' ],
1061
+ previous: getPreData,
1062
+ current: getPostData,
1050
1063
  };
1051
1064
 
1052
1065
  if ( updateKeys.length ) {
@@ -2085,7 +2098,8 @@ export async function getActivityLogs( req, res ) {
2085
2098
  const previous = hit?._source?.previous;
2086
2099
  const current=hit?._source?.current;
2087
2100
  const logType =hit?._source?.logType;
2088
- respo = findDifferences( previous, current, logType );
2101
+ const logSubType =hit?._source?.logSubType === 'documentUpload'? 'documentsUpload': hit?._source?.logSubType;
2102
+ respo = findDifferences( previous, current, logType, logSubType );
2089
2103
  hit._source.updatedValue = respo;
2090
2104
  temp.push( hit?._source );
2091
2105
  } else {
@@ -2104,15 +2118,15 @@ export async function getActivityLogs( req, res ) {
2104
2118
  }
2105
2119
 
2106
2120
 
2107
- function findDifferences( previous, current, logType, path = '' ) {
2121
+ function findDifferences( previous, current, logType, logSubType, path = '' ) {
2108
2122
  const dbKeys = JSON.parse( process.env.DB_KEYS );
2109
2123
  const ignoredKeys = new Set( [
2110
2124
  '_id', 'updatedAt', 'createdAt', 'password', 'clientId',
2111
2125
  'storeId', 'refreshToken', 'employeeId', 'fcmToken', 'permission',
2112
2126
  ] );
2113
-
2127
+ const documents = dbKeys.DOCUMENTS;
2114
2128
  // Get correct key mapping based on logType
2115
- const keyMapping = dbKeys.DOCUMENTS[logType] || {};
2129
+ const keyMapping = logType == 'stores' ?documents.stores: logType == 'users' ?documents.users :logSubType=='reportConfig'?documents.reports: logType=='brandInfo'?documents.client:documents.client;
2116
2130
 
2117
2131
  let differences = {};
2118
2132
 
@@ -2123,7 +2137,7 @@ function findDifferences( previous, current, logType, path = '' ) {
2123
2137
  const currValue = current[key];
2124
2138
 
2125
2139
  if ( typeof prevValue === 'object' && typeof currValue === 'object' && prevValue !== null && currValue !== null ) {
2126
- const nestedDiffs = findDifferences( prevValue, currValue, logType, `${path}${key}.` );
2140
+ const nestedDiffs = findDifferences( prevValue, currValue, logType, logSubType, `${path}${key}.` );
2127
2141
  Object.assign( differences, nestedDiffs );
2128
2142
  } else if ( prevValue !== currValue ) {
2129
2143
  if (
@@ -2139,7 +2153,7 @@ function findDifferences( previous, current, logType, path = '' ) {
2139
2153
  // **Transform & Filter Differences**
2140
2154
  let updatedDifferences = {};
2141
2155
  Object.keys( differences ).forEach( ( key ) => {
2142
- let newKey = key.replace( /spocDetails\.\d+\./, 'spocDetails.' );
2156
+ let newKey = key.replace( /spocDetails\.\d+\./, 'spocDetails.' ).replace( /WhitelistesIps\.\d+/, 'Whitelisted Ips' );
2143
2157
  let diff = differences[key];
2144
2158
 
2145
2159
  if ( newKey.toLowerCase().includes( 'isactive' ) ) {
@@ -2154,11 +2168,21 @@ function findDifferences( previous, current, logType, path = '' ) {
2154
2168
  newKey = userFriendlyKey;
2155
2169
  }
2156
2170
 
2157
- if ( newKey === 'Infra Email Alert' ) {
2158
- diff.previous = diff.previous ? 'Enabled' : 'Disabled';
2159
- diff.current = diff.current ? 'Enabled' : 'Disabled';
2171
+ if ( newKey === 'Infra Email Alert' || newKey === 'Ip Whitelist' || newKey === 'Excluded Area'|| newKey === 'Passer By Data'|| newKey === 'Normalized'|| newKey === 'Billing'|| newKey === 'Camera'|| newKey === 'Footfall Directory'|| newKey === 'NOB'|| newKey === 'New Traffic'|| newKey === 'Trax'|| newKey === 'New Zone'|| newKey === 'New Reports'|| newKey === 'New Dashboard'|| newKey === 'Stream Type' ) {
2172
+ diff.previous = ( diff.previous == true || diff.previous == 'Enabled' ) ? 'Enabled' : 'Disabled';
2173
+ diff.current = ( diff.current == true || diff.current == 'Enabled' ) ? 'Enabled' : 'Disabled';
2174
+ }
2175
+ if ( newKey === 'Mat Enabled' ) {
2176
+ diff.previous = ( diff.previous == true || diff.previous == 'Enabled' )?'Enabled' : 'Disabled';
2177
+ diff.current = ( diff.current == true || diff.current == 'Enabled' ) ? 'Enabled' : 'Disabled';
2178
+ }
2179
+
2180
+ if ( newKey === 'Two Factor Authentication' ) {
2181
+ diff.previous = ( diff.previous == true || diff.previous == 'Enabled' ) ? 'Enabled' : 'Disabled';
2182
+ diff.current = ( diff.current == true || diff.current == 'Enabled' ) ? 'Enabled' : 'Disabled';
2160
2183
  }
2161
2184
 
2185
+
2162
2186
  // **Transform Roles Permission Keys**
2163
2187
  const rolesPermissionMatch = newKey.match( /rolespermission\.(\d+)\.modules\.(\d+)\.(isAdd|isEdit)/ );
2164
2188
  if ( rolesPermissionMatch ) {