tango-app-api-client 3.4.0-beta.0 → 3.4.0-beta.10

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.
@@ -10,16 +10,18 @@ import { aggregateTickets } from '../service/tangoticket.service.js';
10
10
  import { join } from 'path';
11
11
  import { readFileSync } from 'fs';
12
12
  import handlebars from 'handlebars';
13
- import { countDocumentsGroup, createGroupModel, findOneGroup } from '../service/group.service.js';
13
+ import { countDocumentsGroup, createGroupModel } from '../service/group.service.js';
14
14
  // import { deleteOneAuthentication } from '../service/authentication.service.js';
15
15
  import { createBilling } from '../service/billing.service.js';
16
16
  import { createPaymentAccount } from '../service/paymentAccount.service.js';
17
17
  import { countDocumentsClusters, createclusterModel } from '../service/cluster.service.js';
18
18
  import { countDocumentsTeams } from '../service/teams.service.js';
19
+ import { createauditConfig, updateauditConfig, aggregateAuditconfig } from '../service/auditConfig.service.js';
20
+ import { findOnerevopConfig, createrevopConfig, updaterevopConfig } from '../service/revopConfig.service.js';
19
21
 
20
22
  export async function create( req, res ) {
21
23
  try {
22
- const url = JSON.parse( process.env.URL );
24
+ // const url = JSON.parse( process.env.URL );
23
25
  const openSearch = JSON.parse( process.env.OPENSEARCH );
24
26
  const inputData = req.body;
25
27
  const countQuery = [
@@ -96,7 +98,7 @@ export async function create( req, res ) {
96
98
  record.featureConfigs.isNewZone = true;
97
99
  }
98
100
  if ( data.productName === 'tangoTrax' ) {
99
- record.featureConfigs. isTrax= true;
101
+ record.featureConfigs.isTrax = true;
100
102
  }
101
103
  }
102
104
  }
@@ -178,125 +180,118 @@ export async function create( req, res ) {
178
180
 
179
181
  await createBilling( primaryBillingGroup );
180
182
 
181
- const createdGroup = await findOneGroup( { clientId: insertedClientRecord.clientId, isDefault: true }, {} );
182
-
183
- let oldGroup = {
184
- '_id': createdGroup._id,
185
- 'client_id': createdGroup.clientId,
186
- 'groupName': createdGroup.groupName,
187
- 'description': createdGroup.description,
188
- 'storeList': createdGroup.storeList,
189
- };
190
-
191
-
192
- await postApi( `${url.oldapidomain}/oldGroupAdd`, [ oldGroup ] );
193
-
194
183
  // For old dashboard insert
184
+ // const createdGroup = await findOneGroup( { clientId: insertedClientRecord.clientId, isDefault: true }, {} );
185
+ // let oldGroup = {
186
+ // '_id': createdGroup._id,
187
+ // 'client_id': createdGroup.clientId,
188
+ // 'groupName': createdGroup.groupName,
189
+ // 'description': createdGroup.description,
190
+ // 'storeList': createdGroup.storeList,
191
+ // };
192
+ // await postApi( `${url.oldapidomain}/oldGroupAdd`, [ oldGroup ] );
193
+
194
+ // const oldBrandInsertData = {
195
+ // '_id': insertedClientRecord._id,
196
+ // 'brandName': insertedClientRecord.clientName,
197
+ // 'brandIndex': insertedClientRecord.tangoId,
198
+ // 'client_id': insertedClientRecord.clientId,
199
+ // 'phone': user.mobileNumber,
200
+ // 'email': user.email,
201
+ // 'dialCode': user.countryCode,
202
+ // 'name': user.userName,
203
+ // 'cameraCount': insertedClientRecord.planDetails.totalCamera,
204
+ // 'apiKey': insertedClientRecord.clientApi.apiKey,
205
+ // 'clientStatus': insertedClientRecord.status,
206
+ // 'client_type': insertedClientRecord.planDetails.paymentStatus,
207
+ // 'activeMenu': [
208
+ // 'reports',
209
+ // 'birdsEye',
210
+ // 'tangoZone',
211
+ // 'tangoTraffic',
212
+ // 'support',
213
+ // ],
214
+ // 'planType': insertedClientRecord.planDetails.subscriptionPeriod,
215
+ // 'storeCount': insertedClientRecord.planDetails.totalStores,
216
+ // 'squareFeet': insertedClientRecord.planDetails.storeSize,
217
+ // 'subscription': insertedClientRecord.planDetails.subscriptionType,
218
+ // 'subscription_status': true,
219
+ // 'subscribed_features': {
220
+ // 'tango_traffic': false,
221
+ // 'tango_zone': false,
222
+ // 'tango_revop': false,
223
+ // 'tango_storeops': false,
224
+ // 'controlroom': false,
225
+ // 'live_data': false,
226
+ // 'normalization_features': false,
227
+ // 'actual_features': false,
228
+ // },
229
+ // 'store_added_status': true,
230
+ // 'terms_conditions': true,
231
+ // 'otp_verified': true,
232
+ // 'price': 6510,
233
+ // 'currency_type': 'rupees',
234
+ // 'domains': [],
235
+ // 'store_radius_config': 500,
236
+ // };
237
+
238
+ // insertedClientRecord.planDetails.product.forEach( ( element ) => {
239
+ // if ( element.productName === 'tangoTraffic' ) {
240
+ // oldBrandInsertData.subscribed_features.tango_traffic = true;
241
+ // }
242
+ // if ( element.productName === 'tangoZone' ) {
243
+ // oldBrandInsertData.subscribed_features.tango_zone = true;
244
+ // }
245
+ // if ( element.productName === 'prioritySupport' ) {
246
+ // oldBrandInsertData.subscribed_features.tango_storeops = true;
247
+ // }
248
+ // } );
249
+
250
+ // switch ( insertedClientRecord.status ) {
251
+ // case 'active':
252
+ // oldBrandInsertData.clientStatus = 'live';
253
+ // break;
254
+ // case 'hold':
255
+ // oldBrandInsertData.clientStatus = 'hold';
256
+ // break;
257
+ // case 'suspended':
258
+ // oldBrandInsertData.clientStatus = 'suspended';
259
+ // break;
260
+ // case 'deactive':
261
+ // oldBrandInsertData.clientStatus = 'deactivated';
262
+ // break;
263
+ // default:
264
+ // oldBrandInsertData.clientStatus = 'live';
265
+ // }
266
+
267
+ // switch ( insertedClientRecord.planDetails.paymentStatus ) {
268
+ // case 'free':
269
+ // oldBrandInsertData.client_type = 'free';
270
+ // break;
271
+ // case 'trial':
272
+ // oldBrandInsertData.client_type = 'trial';
273
+ // break;
274
+ // case 'paid':
275
+ // oldBrandInsertData.client_type = 'paid';
276
+ // break;
277
+ // default:
278
+ // oldBrandInsertData.client_type = 'trial';
279
+ // }
280
+ // await postApi( `${url.oldapidomain}/oldBrandAdd`, oldBrandInsertData );
281
+
282
+ // const oldDefaultRolesInsertData = {
283
+ // '_id': user._id,
284
+ // 'client_id': insertedClientRecord.clientId,
285
+ // 'brandId': insertedClientRecord._id,
286
+ // 'name': user.userName,
287
+ // 'email': user.email,
288
+ // 'phone': user.mobileNumber,
289
+ // 'password': user.password,
290
+ // 'role': 'storesuperadmin',
291
+ // };
292
+ // await postApi( `${url.oldapidomain}/oldDefaultRoleInsert`, oldDefaultRolesInsertData );
195
293
 
196
294
 
197
- const oldBrandInsertData = {
198
- '_id': insertedClientRecord._id,
199
- 'brandName': insertedClientRecord.clientName,
200
- 'brandIndex': insertedClientRecord.tangoId,
201
- 'client_id': insertedClientRecord.clientId,
202
- 'phone': user.mobileNumber,
203
- 'email': user.email,
204
- 'dialCode': user.countryCode,
205
- 'name': user.userName,
206
- 'cameraCount': insertedClientRecord.planDetails.totalCamera,
207
- 'apiKey': insertedClientRecord.clientApi.apiKey,
208
- 'clientStatus': insertedClientRecord.status,
209
- 'client_type': insertedClientRecord.planDetails.paymentStatus,
210
- 'activeMenu': [
211
- 'reports',
212
- 'birdsEye',
213
- 'tangoZone',
214
- 'tangoTraffic',
215
- 'support',
216
- ],
217
- 'planType': insertedClientRecord.planDetails.subscriptionPeriod,
218
- 'storeCount': insertedClientRecord.planDetails.totalStores,
219
- 'squareFeet': insertedClientRecord.planDetails.storeSize,
220
- 'subscription': insertedClientRecord.planDetails.subscriptionType,
221
- 'subscription_status': true,
222
- 'subscribed_features': {
223
- 'tango_traffic': false,
224
- 'tango_zone': false,
225
- 'tango_revop': false,
226
- 'tango_storeops': false,
227
- 'controlroom': false,
228
- 'live_data': false,
229
- 'normalization_features': false,
230
- 'actual_features': false,
231
- },
232
- 'store_added_status': true,
233
- 'terms_conditions': true,
234
- 'otp_verified': true,
235
- 'price': 6510,
236
- 'currency_type': 'rupees',
237
- 'domains': [],
238
- 'store_radius_config': 500,
239
- };
240
-
241
- insertedClientRecord.planDetails.product.forEach( ( element ) => {
242
- if ( element.productName === 'tangoTraffic' ) {
243
- oldBrandInsertData.subscribed_features.tango_traffic = true;
244
- }
245
- if ( element.productName === 'tangoZone' ) {
246
- oldBrandInsertData.subscribed_features.tango_zone = true;
247
- }
248
- if ( element.productName === 'prioritySupport' ) {
249
- oldBrandInsertData.subscribed_features.tango_storeops = true;
250
- }
251
- } );
252
-
253
- switch ( insertedClientRecord.status ) {
254
- case 'active':
255
- oldBrandInsertData.clientStatus = 'live';
256
- break;
257
- case 'hold':
258
- oldBrandInsertData.clientStatus = 'hold';
259
- break;
260
- case 'suspended':
261
- oldBrandInsertData.clientStatus = 'suspended';
262
- break;
263
- case 'deactive':
264
- oldBrandInsertData.clientStatus = 'deactivated';
265
- break;
266
- default:
267
- oldBrandInsertData.clientStatus = 'live';
268
- }
269
-
270
- switch ( insertedClientRecord.planDetails.paymentStatus ) {
271
- case 'free':
272
- oldBrandInsertData.client_type = 'free';
273
- break;
274
- case 'trial':
275
- oldBrandInsertData.client_type = 'trial';
276
- break;
277
- case 'paid':
278
- oldBrandInsertData.client_type = 'paid';
279
- break;
280
- default:
281
- oldBrandInsertData.client_type = 'trial';
282
- }
283
-
284
-
285
- const oldDefaultRolesInsertData = {
286
- '_id': user._id,
287
- 'client_id': insertedClientRecord.clientId,
288
- 'brandId': insertedClientRecord._id,
289
- 'name': user.userName,
290
- 'email': user.email,
291
- 'phone': user.mobileNumber,
292
- 'password': user.password,
293
- 'role': 'storesuperadmin',
294
- };
295
-
296
- await postApi( `${url.oldapidomain}/oldBrandAdd`, oldBrandInsertData );
297
-
298
- await postApi( `${url.oldapidomain}/oldDefaultRoleInsert`, oldDefaultRolesInsertData );
299
-
300
295
  const logObj = {
301
296
  clientId: insertedClientRecord.clientId,
302
297
  userName: req.user?.userName,
@@ -678,7 +673,7 @@ export async function detailedAllClientCount( req, res ) {
678
673
  if ( result.length == 0 ) {
679
674
  return res.sendError( 'No Data Found', 204 );
680
675
  }
681
- result[0].activeStoresCount = activeStores.length>0?Math.abs( activeStores.length - yettoInstallCount.length ):0;
676
+ result[0].activeStoresCount = activeStores.length > 0 ? Math.abs( activeStores.length - yettoInstallCount.length ) : 0;
682
677
  result[0].activeCameraCount = activeCameras;
683
678
  return res.sendSuccess( { result: result } );
684
679
  } catch ( error ) {
@@ -697,7 +692,7 @@ export async function updateBrandInfo( req, res ) {
697
692
  try {
698
693
  const bucket = JSON.parse( process.env.BUCKET );
699
694
  const openSearch = JSON.parse( process.env.OPENSEARCH );
700
- const url = JSON.parse( process.env.URL );
695
+ // const url = JSON.parse( process.env.URL );
701
696
  let updateKeys = [];
702
697
 
703
698
  if ( req.files?.logo ) {
@@ -769,7 +764,7 @@ export async function updateBrandInfo( req, res ) {
769
764
  };
770
765
 
771
766
  // Map and rename keys from current client info for UI display and logging
772
- const newData ={
767
+ const newData = {
773
768
  RegisteredCompanyName: getPosCientInfo?.profileDetails?.registeredCompanyName,
774
769
  IndustryType: getPosCientInfo?.profileDetails?.industry,
775
770
  FirmType: getPosCientInfo?.profileDetails?.clientType,
@@ -824,26 +819,24 @@ export async function updateBrandInfo( req, res ) {
824
819
  await updateManyUser( { clientId: req.params?.id }, { isActive: false } );
825
820
  }
826
821
 
827
- const { data } = await getApi( `${url.oldapidomain}/oldBrandGet/${req.params?.id}` );
828
-
829
- switch ( req.body?.status ) {
830
- case 'active':
831
- data.clientStatus = 'live';
832
- break;
833
- case 'hold':
834
- data.clientStatus = 'hold';
835
- break;
836
- case 'suspended':
837
- data.clientStatus = 'suspended';
838
- break;
839
- case 'deactive':
840
- data.clientStatus = 'deactivated';
841
- break;
842
- default:
843
- data.clientStatus = 'live';
844
- }
845
-
846
- await postApi( `${url.oldapidomain}/oldBrandUpdate/${data?._id}`, { clientStatus: data.clientStatus } );
822
+ // const { data } = await getApi( `${url.oldapidomain}/oldBrandGet/${req.params?.id}` );
823
+ // switch ( req.body?.status ) {
824
+ // case 'active':
825
+ // data.clientStatus = 'live';
826
+ // break;
827
+ // case 'hold':
828
+ // data.clientStatus = 'hold';
829
+ // break;
830
+ // case 'suspended':
831
+ // data.clientStatus = 'suspended';
832
+ // break;
833
+ // case 'deactive':
834
+ // data.clientStatus = 'deactivated';
835
+ // break;
836
+ // default:
837
+ // data.clientStatus = 'live';
838
+ // }
839
+ // await postApi( `${url.oldapidomain}/oldBrandUpdate/${data?._id}`, { clientStatus: data.clientStatus } );
847
840
 
848
841
  if ( updateAck ) {
849
842
  return res.sendSuccess( { result: 'Updated Successfully' } );
@@ -955,7 +948,7 @@ export async function updateSignatoryDetails( req, res ) {
955
948
  export async function updateTicketConfiguration( req, res ) {
956
949
  try {
957
950
  const openSearch = JSON.parse( process.env.OPENSEARCH );
958
- const fields ={
951
+ const fields = {
959
952
  'ticketConfigs.downTimeType': 1,
960
953
  'ticketConfigs.installationReAssign': 1,
961
954
  'ticketConfigs.infraDownTime': 1,
@@ -996,7 +989,7 @@ export async function updateTicketConfiguration( req, res ) {
996
989
 
997
990
  // Map and rename keys from previous client info for UI display and logging
998
991
  const oldData = {
999
- InfraDowntimeType: findClient?.ticketConfigs?.downTimeType,
992
+ InfraDowntimeType: findClient?.ticketConfigs?.downTimeType == 0 ? 'Single Camera' : 'All Cameras',
1000
993
  AutoReAssignInstallation: findClient?.ticketConfigs?.installationReAssign,
1001
994
  InfraDowntime: findClient?.ticketConfigs?.infraDownTime,
1002
995
  InfraFiles: findClient?.ticketConfigs?.MinFilesCount,
@@ -1008,8 +1001,8 @@ export async function updateTicketConfiguration( req, res ) {
1008
1001
  };
1009
1002
 
1010
1003
  // Map and rename keys from current client info for UI display and logging
1011
- const newData ={
1012
- InfraDowntimeType: updatedClient?.ticketConfigs?.downTimeType,
1004
+ const newData = {
1005
+ InfraDowntimeType: updatedClient?.ticketConfigs?.downTimeType == 0 ? 'Single Camera' : 'All Cameras',
1013
1006
  AutoReAssignInstallation: updatedClient?.ticketConfigs?.installationReAssign,
1014
1007
  InfraDowntime: updatedClient?.ticketConfigs?.infraDownTime,
1015
1008
  InfraFiles: updatedClient?.ticketConfigs?.MinFilesCount,
@@ -1056,7 +1049,7 @@ export async function updateTicketConfiguration( req, res ) {
1056
1049
  export async function updateFeatureConfiguration( req, res ) {
1057
1050
  try {
1058
1051
  const openSearch = JSON.parse( process.env.OPENSEARCH );
1059
- const url = JSON.parse( process.env.URL );
1052
+ // const url = JSON.parse( process.env.URL );
1060
1053
 
1061
1054
  // Get updated client Feature configuration before the update operation (fetch selected fields only)
1062
1055
  const previousData = await findOneClient( { clientId: req.params?.id }, { featureConfigs: 1 } );
@@ -1077,56 +1070,47 @@ export async function updateFeatureConfiguration( req, res ) {
1077
1070
  // Check if request body has any fields to update
1078
1071
  if ( Object.keys( inputData ).length > 0 ) {
1079
1072
  Object.keys( inputData ).forEach( ( element ) => {
1080
- element === 'billableCalculation'? 'potentialCalculation': element; // Replace 'billableCalculation' with 'potentialCalculation' if present
1073
+ element === 'billableCalculation' ? 'potentialCalculation' : element; // Replace 'billableCalculation' with 'potentialCalculation' if present
1081
1074
  updateKeys.push( camelCaseToWords( element ) ); // Convert camelCase field name to readable format and add to updateKeys
1082
1075
  } );
1083
1076
  }
1084
1077
 
1085
1078
  const user = req.user;
1086
1079
 
1087
- const { data } = await getApi( `${url.oldapidomain}/oldBrandGet/${req.params?.id}` );
1088
-
1089
- if ( inputData?.open ) {
1090
- data.brandConfigs.storeOpenTime = inputData?.open;
1091
- }
1092
-
1093
- if ( inputData?.close ) {
1094
- data.brandConfigs.storeCloseTime = inputData?.open;
1095
- }
1096
-
1097
- if ( inputData?.missedOpportunityCalculation ) {
1098
- data.brandConfigs.missedOpportunityCalculate = inputData?.missedOpportunityCalculation;
1099
- }
1100
-
1101
- if ( inputData?.conversionCalculation ) {
1102
- data.brandConfigs.conversionCalculate = inputData?.conversionCalculation;
1103
- }
1104
-
1105
- if ( inputData?.billableCalculation ) {
1106
- data.brandConfigs.billableCalculate = inputData?.billableCalculation;
1107
- }
1108
-
1109
- if ( inputData?.bouncedLimitCondition ) {
1110
- data.brandConfigs.bouncedConfigTime = data.brandConfigs.bouncedConfigTime.replace( /^.+(?=\d)/, inputData?.bouncedLimitCondition );
1111
- data.brandConfigs.missedOpportunityEndTime = data.brandConfigs.missedOpportunityEndTime.replace( /^.+(?=\d)/, inputData?.bouncedLimitCondition );
1112
- }
1113
-
1114
- if ( inputData?.bouncedLimitValue ) {
1115
- data.brandConfigs.bouncedConfigTime = data.brandConfigs.bouncedConfigTime.replace( /\d+/, inputData?.bouncedLimitValue );
1116
- data.brandConfigs.missedOpportunityStartTime = data.brandConfigs.missedOpportunityStartTime.replace( /\d+/, inputData?.bouncedLimitValue );
1117
- }
1118
-
1119
- if ( inputData?.conversionCondition ) {
1120
- data.brandConfigs.conversionConfigTime = data.brandConfigs.conversionConfigTime.replace( /^.+(?=\d)/, inputData?.conversionCondition );
1121
- data.brandConfigs.missedOpportunityStartTime = data.brandConfigs.missedOpportunityStartTime.replace( /^.+(?=\d)/, inputData?.conversionCondition );
1122
- }
1123
-
1124
- if ( inputData?.conversionValue ) {
1125
- data.brandConfigs.conversionConfigTime = data.brandConfigs.conversionConfigTime.replace( /\d+/, inputData?.conversionValue );
1126
- data.brandConfigs.missedOpportunityEndTime = data.brandConfigs.missedOpportunityEndTime.replace( /\d+/, inputData?.conversionValue );
1127
- }
1080
+ // const { data } = await getApi( `${url.oldapidomain}/oldBrandGet/${req.params?.id}` );
1081
+ // if ( inputData?.open ) {
1082
+ // data.brandConfigs.storeOpenTime = inputData?.open;
1083
+ // }
1084
+ // if ( inputData?.close ) {
1085
+ // data.brandConfigs.storeCloseTime = inputData?.open;
1086
+ // }
1087
+ // if ( inputData?.missedOpportunityCalculation ) {
1088
+ // data.brandConfigs.missedOpportunityCalculate = inputData?.missedOpportunityCalculation;
1089
+ // }
1090
+ // if ( inputData?.conversionCalculation ) {
1091
+ // data.brandConfigs.conversionCalculate = inputData?.conversionCalculation;
1092
+ // }
1093
+ // if ( inputData?.billableCalculation ) {
1094
+ // data.brandConfigs.billableCalculate = inputData?.billableCalculation;
1095
+ // }
1096
+ // if ( inputData?.bouncedLimitCondition ) {
1097
+ // data.brandConfigs.bouncedConfigTime = data.brandConfigs.bouncedConfigTime.replace( /^.+(?=\d)/, inputData?.bouncedLimitCondition );
1098
+ // data.brandConfigs.missedOpportunityEndTime = data.brandConfigs.missedOpportunityEndTime.replace( /^.+(?=\d)/, inputData?.bouncedLimitCondition );
1099
+ // }
1100
+ // if ( inputData?.bouncedLimitValue ) {
1101
+ // data.brandConfigs.bouncedConfigTime = data.brandConfigs.bouncedConfigTime.replace( /\d+/, inputData?.bouncedLimitValue );
1102
+ // data.brandConfigs.missedOpportunityStartTime = data.brandConfigs.missedOpportunityStartTime.replace( /\d+/, inputData?.bouncedLimitValue );
1103
+ // }
1104
+ // if ( inputData?.conversionCondition ) {
1105
+ // data.brandConfigs.conversionConfigTime = data.brandConfigs.conversionConfigTime.replace( /^.+(?=\d)/, inputData?.conversionCondition );
1106
+ // data.brandConfigs.missedOpportunityStartTime = data.brandConfigs.missedOpportunityStartTime.replace( /^.+(?=\d)/, inputData?.conversionCondition );
1107
+ // }
1108
+ // if ( inputData?.conversionValue ) {
1109
+ // data.brandConfigs.conversionConfigTime = data.brandConfigs.conversionConfigTime.replace( /\d+/, inputData?.conversionValue );
1110
+ // data.brandConfigs.missedOpportunityEndTime = data.brandConfigs.missedOpportunityEndTime.replace( /\d+/, inputData?.conversionValue );
1111
+ // }
1112
+ // await postApi( `${url.oldapidomain}/oldBrandUpdate/${data?._id}`, { brandConfigs: data.brandConfigs } );
1128
1113
 
1129
- await postApi( `${url.oldapidomain}/oldBrandUpdate/${data?._id}`, { brandConfigs: data.brandConfigs } );
1130
1114
  const keysArray = [
1131
1115
  'isExcludedArea', 'isPasserByData', 'isNormalized', 'isbillingDisabled',
1132
1116
  'isCameraDisabled', 'isFootfallDirectory', 'isNOB', 'isNewTraffic',
@@ -1136,9 +1120,9 @@ export async function updateFeatureConfiguration( req, res ) {
1136
1120
  const oldData = {
1137
1121
  StoreOpenTime: previousData?.featureConfigs?.open,
1138
1122
  StoreCloseTime: previousData?.featureConfigs?.close,
1139
- ConversionCalculations: previousData?.featureConfigs?.conversionCalculation,
1140
- MissedOpportunityCalculation: previousData?.featureConfigs?.missedOpportunityCalculation,
1141
- PotentialCalculations: previousData?.featureConfigs?.billableCalculation,
1123
+ ConversionCalculations: previousData?.featureConfigs?.conversionCalculation == 'footfall-count' ? 'Footfall Count' : postData?.featureConfigs?.conversionCalculation == 'engagers-count' ? 'Engagers Count' : 'Potential Entities',
1124
+ MissedOpportunityCalculation: previousData?.featureConfigs?.missedOpportunityCalculation == 'engagers-conversion' ? 'Engagers - Conversion' : 'Potential Entities - Conversion',
1125
+ PotentialCalculations: previousData?.featureConfigs?.billableCalculation == 'footfall-count' ? 'Footfall Count' : 'Engagers Count',
1142
1126
  ConversionCondition: previousData?.featureConfigs?.conversion.condition,
1143
1127
  ConversionValue: previousData?.featureConfigs?.conversion.value,
1144
1128
  MissedOpportunityFromCondition: previousData?.featureConfigs?.missedOpportunityFrom?.condition,
@@ -1149,33 +1133,32 @@ export async function updateFeatureConfiguration( req, res ) {
1149
1133
  BouncedLimitValue: previousData?.featureConfigs?.bouncedLimit?.value,
1150
1134
  InfraAlertValue: previousData?.featureConfigs?.infraAlert?.value,
1151
1135
  InfraAlertCondition: previousData?.featureConfigs?.infraAlert?.condition,
1152
- ConversionCalculations: previousData?.featureConfigs?.conversionCalculation,
1153
- ExcludedArea: previousData?.featureConfigs?.isExcludedArea ==true ? 'Enable': 'Disable',
1154
- PasserBydata: previousData?.featureConfigs?.isPasserByData ==true ? 'Enable': 'Disable',
1155
- NormalizedDataDuringDowntime: previousData?.featureConfigs?.isNormalized ==true ? 'Enable': 'Disable',
1156
- Billing: previousData?.featureConfigs?.isbillingDisabled ==true ? 'Enable': 'Disable',
1157
- CameraBlurring: previousData?.featureConfigs?.isCameraDisabled ==true ? 'Enable': 'Disable',
1158
- FootfallDirectory: previousData?.featureConfigs?.isFootfallDirectory ==true ? 'Enable': 'Disable',
1159
- NOBStatus: previousData?.featureConfigs?.isNOB ==true ? 'Enable': 'Disable',
1160
- EnableAnalyze: previousData?.featureConfigs?.isNewDashboard ==true ? 'Enable': 'Disable',
1161
- Traffic: previousData?.featureConfigs?.isNewTraffic==true ? 'Enable': 'Disable',
1162
- Zone: previousData?.featureConfigs?.isNewZone ==true ? 'Enable': 'Disable',
1163
- Zonev2: previousData?.featureConfigs?.isNewZoneV2 ==true ? 'Enable': 'Disable',
1164
- Reports: previousData?.featureConfigs?.isNewReports ==true ? 'Enable': 'Disable',
1165
- Trax: previousData?.featureConfigs?.isTrax ==true ? 'Enable': 'Disable',
1166
- StreamType: previousData?.featureConfigs?.streamBy =='Edge' ? 'Edge App': 'RTSP',
1167
- FootfallDirectoryOnlyAudit: previousData?.featureConfigs?.isFootfallDirectoryAudit ==true ? 'Enable': 'Disable',
1168
- FootfallDirectoryOnlyFew: previousData?.featureConfigs?.isFootfallDirectoryLimit ==true ? 'Enable': 'Disable',
1136
+ ExcludedArea: previousData?.featureConfigs?.isExcludedArea == true ? 'Enabled' : 'Disabled',
1137
+ PasserBydata: previousData?.featureConfigs?.isPasserByData == true ? 'Enabled' : 'Disabled',
1138
+ NormalizedDataDuringDowntime: previousData?.featureConfigs?.isNormalized == true ? 'Enabled' : 'Disabled',
1139
+ Billing: previousData?.featureConfigs?.isbillingDisabled == true ? 'Enabled' : 'Disabled',
1140
+ CameraBlurring: previousData?.featureConfigs?.isCameraDisabled == true ? 'Enabled' : 'Disabled',
1141
+ FootfallDirectory: previousData?.featureConfigs?.isFootfallDirectory == true ? 'Enabled' : 'Disabled',
1142
+ NOBStatus: previousData?.featureConfigs?.isNOB == true ? 'Enabled' : 'Disabled',
1143
+ EnableAnalyze: previousData?.featureConfigs?.isNewDashboard == true ? 'Enabled' : 'Disabled',
1144
+ Traffic: previousData?.featureConfigs?.isNewTraffic == true ? 'Enabled' : 'Disabled',
1145
+ Zone: previousData?.featureConfigs?.isNewZone == true ? 'Enabled' : 'Disabled',
1146
+ Zonev2: previousData?.featureConfigs?.isNewZoneV2 == true ? 'Enabled' : 'Disabled',
1147
+ Reports: previousData?.featureConfigs?.isNewReports == true ? 'Enabled' : 'Disabled',
1148
+ Trax: previousData?.featureConfigs?.isTrax == true ? 'Enabled' : 'Disabled',
1149
+ StreamType: previousData?.featureConfigs?.streamBy == 'Edge' ? 'Edge App' : 'RTSP',
1150
+ FootfallDirectoryOnlyAudit: previousData?.featureConfigs?.isFootfallDirectoryAudit == true ? 'Enabled' : 'Disabled',
1151
+ FootfallDirectoryOnlyFew: previousData?.featureConfigs?.isFootfallDirectoryLimit == true ? 'Enabled' : 'Disabled',
1169
1152
 
1170
1153
  };
1171
1154
 
1172
1155
  // Map and rename keys from current client info for UI display and logging
1173
- const newData ={
1156
+ const newData = {
1174
1157
  StoreOpenTime: postData?.featureConfigs?.open,
1175
1158
  StoreCloseTime: postData?.featureConfigs?.close,
1176
- ConversionCalculations: postData?.featureConfigs?.conversionCalculation,
1177
- MissedOpportunityCalculation: postData?.featureConfigs?.missedOpportunityCalculation,
1178
- PotentialCalculations: postData?.featureConfigs?.billableCalculation,
1159
+ ConversionCalculations: postData?.featureConfigs?.conversionCalculation == 'footfall-count' ? 'Footfall Count' : postData?.featureConfigs?.conversionCalculation == 'engagers-count' ? 'Engagers Count' : 'Potential Entities',
1160
+ MissedOpportunityCalculation: postData?.featureConfigs?.missedOpportunityCalculation == 'engagers-conversion' ? 'Engagers - Conversion' : 'Potential Entities - Conversion',
1161
+ PotentialCalculations: postData?.featureConfigs?.billableCalculation == 'footfall-count' ? 'Footfall Count' : 'Engagers Count',
1179
1162
  ConversionCondition: postData?.featureConfigs?.conversion.condition,
1180
1163
  ConversionValue: postData?.featureConfigs?.conversion.value,
1181
1164
  MissedOpportunityFromCondition: postData?.featureConfigs?.missedOpportunityFrom?.condition,
@@ -1186,23 +1169,22 @@ export async function updateFeatureConfiguration( req, res ) {
1186
1169
  BouncedLimitValue: postData?.featureConfigs?.bouncedLimit?.value,
1187
1170
  InfraAlertValue: postData?.featureConfigs?.infraAlert?.value,
1188
1171
  InfraAlertCondition: postData?.featureConfigs?.infraAlert?.condition,
1189
- ConversionCalculations: postData?.featureConfigs?.conversionCalculation,
1190
- ExcludedArea: postData?.featureConfigs?.isExcludedArea ==true ? 'Enable': 'Disable',
1191
- PasserBydata: postData?.featureConfigs?.isPasserByData ==true ? 'Enable': 'Disable',
1192
- NormalizedDataDuringDowntime: postData?.featureConfigs?.isNormalized ==true ? 'Enable': 'Disable',
1193
- Billing: postData?.featureConfigs?.isbillingDisabled ==true ? 'Enable': 'Disable',
1194
- CameraBlurring: postData?.featureConfigs?.isCameraDisabled ==true ? 'Enable': 'Disable',
1195
- FootfallDirectory: postData?.featureConfigs?.isFootfallDirectory ==true ? 'Enable': 'Disable',
1196
- NOBStatus: postData?.featureConfigs?.isNOB ==true ? 'Enable': 'Disable',
1197
- EnableAnalyze: postData?.featureConfigs?.isNewDashboard ==true ? 'Enable': 'Disable',
1198
- Traffic: postData?.featureConfigs?.isNewTraffic==true ? 'Enable': 'Disable',
1199
- Zone: postData?.featureConfigs?.isNewZone ==true ? 'Enable': 'Disable',
1200
- Zonev2: postData?.featureConfigs?.isNewZoneV2 ==true ? 'Enable': 'Disable',
1201
- Reports: postData?.featureConfigs?.isNewReports ==true ? 'Enable': 'Disable',
1202
- Trax: postData?.featureConfigs?.isTrax ==true ? 'Enable': 'Disable',
1203
- StreamType: postData?.featureConfigs?.streamBy =='Edge' ? 'Edge App': 'RTSP',
1204
- FootfallDirectoryOnlyAudit: postData?.featureConfigs?.isFootfallDirectoryAudit ==true ? 'Enable': 'Disable',
1205
- FootfallDirectoryOnlyFew: postData?.featureConfigs?.isFootfallDirectoryLimit ==true ? 'Enable': 'Disable',
1172
+ ExcludedArea: postData?.featureConfigs?.isExcludedArea == true ? 'Enabled' : 'Disabled',
1173
+ PasserBydata: postData?.featureConfigs?.isPasserByData == true ? 'Enabled' : 'Disabled',
1174
+ NormalizedDataDuringDowntime: postData?.featureConfigs?.isNormalized == true ? 'Enabled' : 'Disabled',
1175
+ Billing: postData?.featureConfigs?.isbillingDisabled == true ? 'Enabled' : 'Disabled',
1176
+ CameraBlurring: postData?.featureConfigs?.isCameraDisabled == true ? 'Enabled' : 'Disabled',
1177
+ FootfallDirectory: postData?.featureConfigs?.isFootfallDirectory == true ? 'Enabled' : 'Disabled',
1178
+ NOBStatus: postData?.featureConfigs?.isNOB == true ? 'Enabled' : 'Disabled',
1179
+ EnableAnalyze: postData?.featureConfigs?.isNewDashboard == true ? 'Enabled' : 'Disabled',
1180
+ Traffic: postData?.featureConfigs?.isNewTraffic == true ? 'Enabled' : 'Disabled',
1181
+ Zone: postData?.featureConfigs?.isNewZone == true ? 'Enabled' : 'Disabled',
1182
+ Zonev2: postData?.featureConfigs?.isNewZoneV2 == true ? 'Enabled' : 'Disabled',
1183
+ Reports: postData?.featureConfigs?.isNewReports == true ? 'Enabled' : 'Disabled',
1184
+ Trax: postData?.featureConfigs?.isTrax == true ? 'Enabled' : 'Disabled',
1185
+ StreamType: postData?.featureConfigs?.streamBy == 'Edge' ? 'Edge App' : 'RTSP',
1186
+ FootfallDirectoryOnlyAudit: postData?.featureConfigs?.isFootfallDirectoryAudit == true ? 'Enabled' : 'Disabled',
1187
+ FootfallDirectoryOnlyFew: postData?.featureConfigs?.isFootfallDirectoryLimit == true ? 'Enabled' : 'Disabled',
1206
1188
 
1207
1189
  };
1208
1190
 
@@ -1246,11 +1228,11 @@ export async function domainDetailsConfiguration( req, res ) {
1246
1228
  const getPreData = await findOneClient(
1247
1229
  { clientId: req.params?.id }, // filter by clientId
1248
1230
  {
1249
- domainName: '$domainConfig.ssoLogin.domainName',
1250
- isEnable: '$domainConfig.ssoLogin.isEnable',
1251
- ipWhitelist: '$domainConfig.ipWhitelisting.enableWhitelisting',
1252
- WhitelistedIps: '$domainConfig.ipWhitelisting.allowedIps',
1253
- TwoFactorAuthentication: '$domainConfig.enableOtp',
1231
+ 'domainConfig.ssoLogin.domainName': 1,
1232
+ 'domainConfig.ssoLogin.isEnable': 1,
1233
+ 'domainConfig.ipWhitelisting.enableWhitelisting': 1,
1234
+ 'domainConfig.ipWhitelisting.allowedIps': 1,
1235
+ 'domainConfig.enableOtp': 1,
1254
1236
  },
1255
1237
  );
1256
1238
  const updateAck = await domainDetailsConfigurationUpdate( {
@@ -1271,35 +1253,35 @@ export async function domainDetailsConfiguration( req, res ) {
1271
1253
  const getPostData = await findOneClient(
1272
1254
  { clientId: req.params?.id }, // Filter by clientId
1273
1255
  {
1274
- domainName: '$domainConfig.ssoLogin.domainName',
1275
- isEnable: '$domainConfig.ssoLogin.isEnable',
1276
- ipWhitelist: '$domainConfig.ipWhitelisting.enableWhitelisting',
1277
- WhitelistedIps: '$domainConfig.ipWhitelisting.allowedIps',
1278
- TwoFactorAuthentication: '$domainConfig.enableOtp',
1256
+ 'domainConfig.ssoLogin.domainName': 1,
1257
+ 'domainConfig.ssoLogin.isEnable': 1,
1258
+ 'domainConfig.ipWhitelisting.enableWhitelisting': 1,
1259
+ 'domainConfig.ipWhitelisting.allowedIps': 1,
1260
+ 'domainConfig.enableOtp': 1,
1279
1261
  },
1280
1262
  );
1281
1263
 
1282
1264
 
1283
1265
  // Map and rename keys from previous client info for UI display and logging
1284
1266
  const oldData = {
1285
- DomainName: getPreData?.domainConfig?.ssoLogin?.domainName,
1286
- IsEnable: getPreData?.domainConfig?.ssoLogin?.isEnable ==true ? 'Enable': 'Disable',
1287
- IPWhitelist: getPreData?.domainConfig?.ipWhitelisting?.enableWhitelisting ==true ? 'Enable': 'Disable',
1288
- WhitelistedIps: ( getPreData?.domainConfig?.ipWhitelisting?.allowedIps ).join( ', ' ),
1289
- TwoFactorAuthentication: getPreData?.domainConfig?.enableOtp ==true ? 'Enable': 'Disable',
1267
+ DomainName: getPreData?.domainConfig?.ssoLogin?.domainName?.join( ', ' ),
1268
+ IsEnable: getPreData?.domainConfig?.ssoLogin?.isEnable == true ? 'Enable' : 'Disable',
1269
+ IPWhitelist: getPreData?.domainConfig?.ipWhitelisting?.enableWhitelisting == true ? 'Enable' : 'Disable',
1270
+ WhitelistedIps: getPreData?.domainConfig?.ipWhitelisting?.allowedIps?.join( ', ' ),
1271
+ TwoFactorAuthentication: getPreData?.domainConfig?.enableOtp == true ? 'Enable' : 'Disable',
1290
1272
 
1291
1273
  };
1292
1274
 
1293
1275
  // Map and rename keys from current client info for UI display and logging
1294
- const newData ={
1295
- DomainName: getPostData?.domainConfig?.ssoLogin?.domainName,
1296
- IsEnable: getPostData?.domainConfig?.ssoLogin?.isEnable ==true ? 'Enable': 'Disable',
1297
- IPWhitelist: getPostData?.domainConfig?.ipWhitelisting?.enableWhitelisting ==true ? 'Enable': 'Disable',
1298
- WhitelistedIps: ( getPostData?.domainConfig?.ipWhitelisting?.allowedIps ).join( ', ' ),
1299
- TwoFactorAuthentication: getPostData?.domainConfig?.enableOtp ==true ? 'Enable': 'Disable',
1276
+ const newData = {
1277
+ DomainName: getPostData?.domainConfig?.ssoLogin?.domainName?.join( ', ' ),
1278
+ IsEnable: getPostData?.domainConfig?.ssoLogin?.isEnable == true ? 'Enable' : 'Disable',
1279
+ IPWhitelist: getPostData?.domainConfig?.ipWhitelisting?.enableWhitelisting == true ? 'Enable' : 'Disable',
1280
+ WhitelistedIps: getPostData?.domainConfig?.ipWhitelisting?.allowedIps?.join( ', ' ),
1281
+ TwoFactorAuthentication: getPostData?.domainConfig?.enableOtp == true ? 'Enable' : 'Disable',
1300
1282
  };
1301
1283
 
1302
-
1284
+ logger.info( { getPreData: getPreData, getPostData: getPostData, newData: newData, oldData: oldData } );
1303
1285
  // Prepare activity log object with all relevant details for OpenSearch logging
1304
1286
  const logObj = {
1305
1287
  clientId: req.params?.id, // ID of the client whose data was updated
@@ -1482,7 +1464,7 @@ export async function auditConfiguration( req, res ) {
1482
1464
  auditConfigs: 1, _id: 0,
1483
1465
  };
1484
1466
  const previousClient = await findOneClient( query, fields );
1485
- previousClient.auditConfigs.ratio = previousClient?.auditConfigs?.ratio? ( previousClient.auditConfigs.ratio )*100 : null;
1467
+ previousClient.auditConfigs.ratio = previousClient?.auditConfigs?.ratio ? ( previousClient.auditConfigs.ratio ) * 100 : null;
1486
1468
  const record = {
1487
1469
  'auditConfigs.count': inputData.count,
1488
1470
  'auditConfigs.audit': inputData.audit,
@@ -1490,20 +1472,22 @@ export async function auditConfiguration( req, res ) {
1490
1472
  };
1491
1473
  await updateOneClient( query, record );
1492
1474
 
1493
-
1494
1475
  // Map and rename keys from previous client info for UI display and logging
1495
1476
  const oldData = {
1496
- AuditStatus: inputData?.audit ==true ? 'Enable': 'Disable',
1497
- MappingPercentage: inputData?.ratio,
1498
- AuditCount: inputData?.count,
1499
-
1477
+ AuditStatus: previousClient?.auditConfigs?.audit == true ? 'Enable' : 'Disable',
1478
+ MappingPercentage: previousClient?.auditConfigs?.ratio,
1479
+ AuditCount: previousClient?.auditConfigs?.count,
1500
1480
  };
1501
1481
 
1482
+ const currentClient = await findOneClient( query, fields );
1483
+ currentClient.auditConfigs.ratio = currentClient?.auditConfigs?.ratio ? ( currentClient.auditConfigs.ratio ) * 100 : null;
1484
+
1502
1485
  // Map and rename keys from current client info for UI display and logging
1503
- const newData ={
1504
- AuditStatus: previousClient.auditConfigs?.audit ==true ? 'Enable': 'Disable',
1505
- MappingPercentage: previousClient.auditConfigs?.ratio,
1506
- AuditCount: previousClient.auditConfigs?.count,
1486
+ const newData = {
1487
+ AuditStatus: currentClient?.auditConfigs?.audit == true ? 'Enable' : 'Disable',
1488
+ MappingPercentage: currentClient?.auditConfigs?.ratio,
1489
+ AuditCount: currentClient?.auditConfigs?.count,
1490
+
1507
1491
  };
1508
1492
  const logObj = {
1509
1493
  clientId: req.params?.id,
@@ -1516,12 +1500,7 @@ export async function auditConfiguration( req, res ) {
1516
1500
  showTo: [ 'tango' ],
1517
1501
  changes: [ `Audit config for client id ${req.params?.id}` ],
1518
1502
  previous: previousClient.auditConfigs,
1519
- current: {
1520
- clientId: req.params?.id,
1521
- count: inputData.count,
1522
- audit: inputData.audit,
1523
- ratio: inputData.ratio,
1524
- },
1503
+ current: currentClient.auditConfigs,
1525
1504
  oldData: oldData,
1526
1505
  newData: newData,
1527
1506
  };
@@ -2280,12 +2259,12 @@ export async function getActivityLogs1( req, res ) {
2280
2259
  try {
2281
2260
  const inputData = req.body;
2282
2261
  const openSearch = JSON.parse( process.env.OPENSEARCH );
2283
- const clientQuery =[
2262
+ const clientQuery = [
2284
2263
  {
2285
2264
  $match: {
2286
2265
  $and: [
2287
2266
  {
2288
- clientId: { $in: inputData },
2267
+ clientId: { $in: [ inputData?.clientId ] },
2289
2268
  },
2290
2269
  ],
2291
2270
  },
@@ -2304,37 +2283,23 @@ export async function getActivityLogs1( req, res ) {
2304
2283
  },
2305
2284
  ];
2306
2285
  const getClientName = await aggregateClient( clientQuery );
2307
- if ( getClientName?.length == 0 || getClientName[0]?.clientName?.length ===0 ) {
2286
+ if ( getClientName?.length == 0 || getClientName[0]?.clientName?.length === 0 ) {
2308
2287
  return res.sendError( 'No Data Found', 204 );
2309
2288
  }
2310
2289
  const query = {
2311
2290
  '_source': [
2312
2291
  'userId', 'userName', 'email', 'date', 'logType', 'logSubType',
2313
- 'changes', 'eventType', 'previous', 'current',
2292
+ 'changes', 'eventType', 'previous', 'current', 'oldData', 'newData',
2314
2293
  ],
2315
2294
  'query': {
2316
2295
  'bool': {
2317
- // 'must': [
2318
- // {
2319
- // 'terms': {
2320
- // 'clientId.keyword': [ req.body.clientId ],
2321
- // },
2322
- // },
2323
- // ],
2324
-
2325
- 'should': [
2326
- {
2327
- 'terms': {
2328
- 'clientId.keyword': [ inputData.clientId ],
2329
- },
2330
- },
2296
+ 'must': [
2331
2297
  {
2332
2298
  'terms': {
2333
- 'clientName.keyword': [ getClientName[0].clientName ], // Add clientName condition
2299
+ 'clientId.keyword': [ req.body.clientId ],
2334
2300
  },
2335
2301
  },
2336
2302
  ],
2337
- 'minimum_should_match': 1, // Ensures at least one condition must match
2338
2303
  },
2339
2304
  },
2340
2305
  'from': ( req.body.offset - 1 ) * req.body.limit,
@@ -2385,18 +2350,22 @@ export async function getActivityLogs1( req, res ) {
2385
2350
  let temp = [];
2386
2351
  if ( totalDocuments ) {
2387
2352
  hits.map( ( hit, i ) => {
2388
- let respo ={};
2389
- hit._source.logSubType = hit._source.logSubType === 'documentUpload'? 'documentsUpload': hit._source.logSubType === 'domainDetails'? 'securityFeatures': hit?._source?.logSubType;
2390
- if ( ( ( hit?._source?.eventType ).match( /update/ ) || ( hit?._source?.eventType ).match( /edit/ ) )&& hit?._source?.previous ) {
2391
- const previous = hit?._source?.previous;
2392
- const current=hit?._source?.current;
2393
- const logType =hit?._source?.logType;
2394
-
2395
- const logSubType =hit?._source?.logSubType;
2396
- respo = findDifferences1( previous, current, logType, logSubType );
2353
+ let respo = {};
2354
+ hit._source.logSubType = hit._source.logSubType === 'documentUpload' ? 'documentsUpload' : hit._source.logSubType === 'domainDetails' ? 'securityFeatures' : hit?._source?.logSubType;
2355
+ if ( ( ( hit?._source?.eventType ).match( /update/ ) || ( hit?._source?.eventType ).match( /edit/ ) ) && hit?._source?.previous ) {
2356
+ const previous = hit?._source?.logType == 'cameras' ? hit?._source?.oldData : hit?._source?.previous;
2357
+ const current = hit?._source?.logType == 'cameras' ? hit?._source?.newData : hit?._source?.current;
2358
+ const logType = hit?._source?.logType;
2359
+ const logSubType = hit?._source?.logSubType;
2360
+ if ( previous && current && hit?._source?.logType == 'cameras' ) {
2361
+ respo = findDifferences( previous, current );
2362
+ } else {
2363
+ respo = findDifferences1( previous, current, logType, logSubType );
2364
+ }
2365
+
2397
2366
  hit._source.updatedValue = respo;
2398
2367
  temp.push( hit?._source );
2399
- hit._source.changes =logSubType === 'ticketConfig'? Object.keys( respo ).map( ( item ) => item ) : hit._source.changes;
2368
+ hit._source.changes = logSubType === 'ticketConfig' ? Object.keys( respo ).map( ( item ) => item ) : hit._source.changes;
2400
2369
  } else {
2401
2370
  temp.push( hit?._source );
2402
2371
  }
@@ -2421,7 +2390,7 @@ function findDifferences1( previous, current, logType, logSubType, path = '' ) {
2421
2390
  ] );
2422
2391
  const documents = dbKeys.DOCUMENTS;
2423
2392
  // Get correct key mapping based on logType
2424
- const keyMapping = logType == 'stores' ?documents.stores: logType == 'users' ?documents.users :logSubType=='reportConfig'?documents.reports: logType=='brandInfo'?documents.client:documents.client;
2393
+ const keyMapping = logType == 'stores' ? documents.stores : logType == 'users' ? documents.users : logSubType == 'reportConfig' ? documents.reports : logType == 'brandInfo' ? documents.client : documents.client;
2425
2394
 
2426
2395
 
2427
2396
  let differences = {};
@@ -2433,7 +2402,7 @@ function findDifferences1( previous, current, logType, logSubType, path = '' ) {
2433
2402
  const currValue = current[key];
2434
2403
 
2435
2404
  if ( typeof prevValue === 'object' && typeof currValue === 'object' && prevValue !== null && currValue !== null ) {
2436
- if ( logSubType!== 'userUpdated' ) {
2405
+ if ( logSubType !== 'userUpdated' ) {
2437
2406
  if ( key == 'spocDetails' ) {
2438
2407
  if ( _.isEqual( prevValue, currValue ) ) {
2439
2408
  continue;
@@ -2441,9 +2410,9 @@ function findDifferences1( previous, current, logType, logSubType, path = '' ) {
2441
2410
  let result = compareArrayObjects( prevValue, currValue );
2442
2411
  differences = { ...differences, ...result };
2443
2412
  }
2444
- } else if ( Array.isArray( prevValue ) && prevValue.every( ( item ) => typeof item === 'string' ) ||Array.isArray( currValue ) && currValue.every( ( item ) => typeof item === 'string' ) ) {
2445
- JSON.stringify( prevValue ) !== JSON.stringify( currValue )?
2446
- differences[`${path}${key}`] = { previous: prevValue.length> 0 ? prevValue.join( ',' ): null, current: currValue.length > 0? currValue.join( ',' ): null } : null;
2413
+ } else if ( Array.isArray( prevValue ) && prevValue.every( ( item ) => typeof item === 'string' ) || Array.isArray( currValue ) && currValue.every( ( item ) => typeof item === 'string' ) ) {
2414
+ JSON.stringify( prevValue ) !== JSON.stringify( currValue ) ?
2415
+ differences[`${path}${key}`] = { previous: prevValue.length > 0 ? prevValue.join( ',' ) : null, current: currValue.length > 0 ? currValue.join( ',' ) : null } : null;
2447
2416
 
2448
2417
  // differences[`${path}${key}`] = { previous: removed.length> 0 ? prevValue.join( ',' ): prevValue.join( ', ' ) :, current: added.length > 0? addedUsers.join( ', ' ) : currValue.join( ',' ) } : null;
2449
2418
  } else {
@@ -2514,13 +2483,13 @@ function findDifferences1( previous, current, logType, logSubType, path = '' ) {
2514
2483
 
2515
2484
  if (
2516
2485
  ( diff.previous === '' || diff.previous === null || ( Array.isArray( diff.previous ) && diff.previous.length === 0 ) ) &&
2517
- diff.current === undefined
2486
+ diff.current === undefined
2518
2487
  ) {
2519
2488
  return;
2520
2489
  }
2521
2490
  if (
2522
2491
  ( diff.current === '' || diff.current === null || ( Array.isArray( diff.current ) && diff.current.length === 0 ) ) &&
2523
- diff.previous === undefined
2492
+ diff.previous === undefined
2524
2493
  ) {
2525
2494
  return;
2526
2495
  }
@@ -2551,7 +2520,7 @@ export async function getActivityLogs( req, res ) {
2551
2520
  try {
2552
2521
  const inputData = req.body;
2553
2522
  const openSearch = JSON.parse( process.env.OPENSEARCH );
2554
- const clientQuery =[
2523
+ const clientQuery = [
2555
2524
  {
2556
2525
  $match: {
2557
2526
  $and: [
@@ -2575,7 +2544,7 @@ export async function getActivityLogs( req, res ) {
2575
2544
  },
2576
2545
  ];
2577
2546
  const getClientName = await aggregateClient( clientQuery );
2578
- if ( getClientName?.length == 0 || getClientName[0]?.clientName?.length ===0 ) {
2547
+ if ( getClientName?.length == 0 || getClientName[0]?.clientName?.length === 0 ) {
2579
2548
  return res.sendError( 'No Data Found', 204 );
2580
2549
  }
2581
2550
  const query = {
@@ -2650,12 +2619,14 @@ export async function getActivityLogs( req, res ) {
2650
2619
  let temp = [];
2651
2620
  if ( totalDocuments ) {
2652
2621
  hits.map( ( hit, i ) => {
2653
- let respo ={};
2654
- hit._source.logSubType = hit._source.logSubType === 'documentUpload'? 'documentsUpload': hit._source.logSubType === 'domainDetails'? 'securityFeatures': hit?._source?.logSubType;
2655
- if ( ( ( hit?._source?.eventType ).match( /update/ ) || ( hit?._source?.eventType ).match( /edit/ ) )&& hit?._source?.previous ) {
2622
+ let respo = {};
2623
+ hit._source.logSubType = hit._source.logSubType === 'documentUpload' ? 'documentsUpload' : hit._source.logSubType === 'domainDetails' ? 'securityFeatures' : hit?._source?.logSubType;
2624
+ if ( ( ( hit?._source?.eventType ).match( /update/ ) || ( hit?._source?.eventType ).match( /edit/ ) ) && hit?._source?.previous ) {
2656
2625
  const previous = hit?._source?.oldData;
2657
- const current=hit?._source?.newData;
2658
- respo = findDifferences( previous, current );
2626
+ const current = hit?._source?.newData;
2627
+ if ( previous && current ) {
2628
+ respo = findDifferences( previous, current );
2629
+ }
2659
2630
  hit._source.updatedValue = respo;
2660
2631
  temp.push( hit?._source );
2661
2632
  // hit._source.changes =logSubType === 'ticketConfig'? Object.keys( respo ).map( ( item ) => item ) : hit._source.changes;
@@ -2674,57 +2645,70 @@ export async function getActivityLogs( req, res ) {
2674
2645
  }
2675
2646
  }
2676
2647
 
2677
- function findDifferences( obj1, obj2 ) {
2678
- let differences = {};
2648
+ function findDifferences( oldData, newData ) {
2649
+ logger.info( { oldData: oldData, newData: newData } );
2650
+ const allKeys = new Set( [ ...Object.keys( oldData ), ...Object.keys( newData ) ] );
2651
+ const diff = {};
2652
+
2653
+ allKeys.forEach( ( key ) => {
2654
+ const previous = key in oldData ? oldData[key] : null;
2655
+ const current = key in newData ? newData[key] : null;
2679
2656
 
2680
- for ( let key in obj1 ) {
2681
- if ( obj1[key] !== obj2[key] ) {
2682
- differences[splitCamelCase( key )] = { previous: obj1[key], current: obj2[key] };
2657
+ // Only include fields that are added or updated (where previous !== current)
2658
+ if ( previous !== current ) {
2659
+ diff[splitCamelCase( key )] = {
2660
+ previous,
2661
+ current,
2662
+ };
2683
2663
  }
2684
- }
2664
+ } );
2685
2665
 
2686
- return differences;
2666
+ return diff;
2687
2667
  }
2688
2668
 
2689
2669
  function splitCamelCase( text ) {
2690
- return text.replace( /([a-z])([A-Z])/g, '$1 $2' );
2691
- }
2692
-
2693
- async function postApi( url, data ) {
2694
- const requestOptions = {
2695
- method: 'POST',
2696
- headers: {
2697
- 'Content-Type': 'application/json',
2698
- 'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
2699
- },
2700
- body: JSON.stringify( data ),
2701
- };
2702
-
2703
- try {
2704
- const response = await fetch( url, requestOptions );
2705
- await response.json();
2706
- } catch ( error ) {
2707
- logger.error( { error: error, message: data, function: 'postApi' } );
2708
- }
2670
+ return text.replace( /([a-z])([A-Z])/g, '$1 $2' ) // Add space between camelCase words
2671
+ .replace( /([a-zA-Z])(\d+)/g, '$1 $2' ) // Add space between letters and numbers
2672
+ .replace( /(\d+)([a-zA-Z])/g, '$1 $2' )
2673
+ .trim()
2674
+ .replace( /^./, ( match ) => match.toUpperCase() ); // Capitalize the first letter
2709
2675
  }
2710
2676
 
2711
- async function getApi( url ) {
2712
- const requestOptions = {
2713
- method: 'GET',
2714
- headers: {
2715
- 'Content-Type': 'application/json',
2716
- 'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
2717
- },
2718
- };
2719
-
2720
- try {
2721
- const response = await fetch( url, requestOptions );
2722
- const responseData = await response.json();
2723
- return responseData;
2724
- } catch ( error ) {
2725
- logger.error( { error: error, message: 'Error in GET request', function: 'getApi' } );
2726
- }
2727
- }
2677
+ // async function postApi( url, data ) {
2678
+ // const requestOptions = {
2679
+ // method: 'POST',
2680
+ // headers: {
2681
+ // 'Content-Type': 'application/json',
2682
+ // 'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
2683
+ // },
2684
+ // body: JSON.stringify( data ),
2685
+ // };
2686
+
2687
+ // try {
2688
+ // const response = await fetch( url, requestOptions );
2689
+ // await response.json();
2690
+ // } catch ( error ) {
2691
+ // logger.error( { error: error, message: data, function: 'postApi' } );
2692
+ // }
2693
+ // }
2694
+
2695
+ // async function getApi( url ) {
2696
+ // const requestOptions = {
2697
+ // method: 'GET',
2698
+ // headers: {
2699
+ // 'Content-Type': 'application/json',
2700
+ // 'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
2701
+ // },
2702
+ // };
2703
+
2704
+ // try {
2705
+ // const response = await fetch( url, requestOptions );
2706
+ // const responseData = await response.json();
2707
+ // return responseData;
2708
+ // } catch ( error ) {
2709
+ // logger.error( { error: error, message: 'Error in GET request', function: 'getApi' } );
2710
+ // }
2711
+ // }
2728
2712
 
2729
2713
 
2730
2714
  export async function csmAssignConfirmation( req, res ) {
@@ -2771,8 +2755,8 @@ function compareArrayObjects( prevArray, currArray ) {
2771
2755
 
2772
2756
  Object.keys( { ...prevObj, ...currObj } ).forEach( ( key ) => {
2773
2757
  if ( prevObj[key] !== currObj[key] && key !== '_id' ) {
2774
- const key1 = key == 'contact'? 'Contact Number': key == 'email'? 'Email ID':key == 'name'?'Name': key == 'designation'?'Designation':key;
2775
- const name = i ==0? 'Primary Spoc': `Alternate Spoc ${i+1}`;
2758
+ const key1 = key == 'contact' ? 'Contact Number' : key == 'email' ? 'Email ID' : key == 'name' ? 'Name' : key == 'designation' ? 'Designation' : key;
2759
+ const name = i == 0 ? 'Primary Spoc' : `Alternate Spoc ${i + 1}`;
2776
2760
  diff[`${name} ${key1}`] = {
2777
2761
  previous: prevObj[key] || 'null',
2778
2762
  current: currObj[key] || 'null',
@@ -2788,3 +2772,120 @@ function compareArrayObjects( prevArray, currArray ) {
2788
2772
 
2789
2773
  return changes;
2790
2774
  }
2775
+
2776
+
2777
+ export async function createAuditConfig( req, res ) {
2778
+ try {
2779
+ await createauditConfig( req.body );
2780
+ return res.sendSuccess( 'created Sucessfully' );
2781
+ } catch ( error ) {
2782
+ logger.error( { error: error, message: req.body, function: 'createAuditConfig' } );
2783
+ return res.sendError( 'Internal Server Error', 500 );
2784
+ }
2785
+ }
2786
+ export async function updateAuditConfig( req, res ) {
2787
+ try {
2788
+ await updateauditConfig( { _id: req.params.id }, req.body );
2789
+ return res.sendSuccess( 'updated Sucessfully' );
2790
+ } catch ( error ) {
2791
+ logger.error( { error: error, message: req.body, function: 'createAuditConfig' } );
2792
+ return res.sendError( 'Internal Server Error', 500 );
2793
+ }
2794
+ }
2795
+ export async function AuditConfiglist( req, res ) {
2796
+ try {
2797
+ let Query = [ {
2798
+ $match: {
2799
+ '$and': [
2800
+ { 'clientId': { $in: req.body.clientId } },
2801
+ ],
2802
+ },
2803
+ } ];
2804
+ if ( req.body.searchValue && req.body.searchValue !== '' ) {
2805
+ const searchCondition = {
2806
+ $match: {
2807
+ $or: [
2808
+ { AuditName: { $regex: req.body.searchValue, $options: 'i' } },
2809
+ { keyWord: { $regex: req.body.searchValue, $options: 'i' } },
2810
+ ],
2811
+ },
2812
+ };
2813
+
2814
+ Query.push( searchCondition );
2815
+ }
2816
+ if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
2817
+ const sortOption = { $sort: { [req.body.sortColumName]: req.body.sortBy } };
2818
+ Query.push( sortOption );
2819
+ } else {
2820
+ const sortOption = { $sort: { 'AuditName': -1 } };
2821
+ Query.push( sortOption );
2822
+ }
2823
+
2824
+ let count = await aggregateAuditconfig( Query );
2825
+
2826
+ if ( req.body.limit && req.body.offset && !req.body.export ) {
2827
+ const skipValue = ( req.body.offset - 1 ) * req.body.limit;
2828
+ const limitValue = Number( req.body.limit );
2829
+
2830
+ const pagination = [
2831
+ { $skip: skipValue },
2832
+ { $limit: limitValue },
2833
+ ];
2834
+
2835
+ Query.push( ...pagination );
2836
+ }
2837
+
2838
+ let result = await aggregateAuditconfig( Query );
2839
+
2840
+ if ( req.body.export && result.length > 0 ) {
2841
+ const exportdata = result.map( ( element ) => {
2842
+ return {
2843
+ 'Audit Name': element.AuditName,
2844
+ 'Keyword': element.keyWord,
2845
+ 'File Type': element.fileType,
2846
+ 'Response Type': element.responseType,
2847
+ 'Status': element.status,
2848
+ };
2849
+ } );
2850
+ await download( exportdata, res );
2851
+ return;
2852
+ }
2853
+ return res.sendSuccess( { result: result, totalCount: count.length } );
2854
+ } catch ( error ) {
2855
+ logger.error( { error: error, message: req.body, function: 'createAuditConfig' } );
2856
+ return res.sendError( 'Internal Server Error', 500 );
2857
+ }
2858
+ }
2859
+
2860
+
2861
+ export async function revopconfig( req, res ) {
2862
+ try {
2863
+ let result = await findOnerevopConfig( { clientId: req.body.clientId } );
2864
+
2865
+ if ( result===null ) {
2866
+ await createrevopConfig( req.body );
2867
+ return res.sendSuccess( 'revopconfig created Sucessfully' );
2868
+ } else {
2869
+ await updaterevopConfig( { clientId: req.body.clientId }, req.body );
2870
+ return res.sendSuccess( 'revopconfig updated Sucessfully' );
2871
+ }
2872
+ } catch ( error ) {
2873
+ logger.error( { error: error, message: req.body, function: 'revopconfig' } );
2874
+ return res.sendError( 'Internal Server Error', 500 );
2875
+ }
2876
+ }
2877
+
2878
+ export async function getrevopconfig( req, res ) {
2879
+ try {
2880
+ let result = await findOnerevopConfig( { clientId: req.query.clientId } );
2881
+ if ( result===null ) {
2882
+ return res.sendError( 'no data found', 204 );
2883
+ }
2884
+ return res.sendSuccess( result );
2885
+ } catch ( error ) {
2886
+ logger.error( { error: error, message: req.query, function: 'revopconfig' } );
2887
+ return res.sendError( 'Internal Server Error', 500 );
2888
+ }
2889
+ }
2890
+
2891
+