tango-app-api-store-zone 3.3.1-beta.23 → 3.3.1-beta.24

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-store-zone",
3
- "version": "3.3.1-beta.23",
3
+ "version": "3.3.1-beta.24",
4
4
  "description": "zone",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -592,7 +592,6 @@ export const customTagListv3 = async ( req, res ) => {
592
592
  ] );
593
593
 
594
594
 
595
- console.log( '🚀 ~ customTagListv3 ~ taggingDetails:', zonefinalTags );
596
595
  return res.sendSuccess( zonefinalTags );
597
596
  }
598
597
 
@@ -1302,37 +1301,40 @@ export const updatezoneTagging = async ( req, res ) => {
1302
1301
 
1303
1302
  export const updateOldData = async ( req, res ) => {
1304
1303
  try {
1305
- let tagDetails = await taggingService.find( {}, { storeId: 1 } );
1304
+ let tagDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName }, { storeId: 1 } );
1305
+
1306
1306
  if ( tagDetails.length ) {
1307
1307
  for ( let [ index, item ] of tagDetails.entries() ) {
1308
1308
  req.body.storeId = item.storeId;
1309
1309
  let camDetails = await getCamTaggingDetails( req, res );
1310
- if ( !camDetails ) {
1311
- logger.error( { message: 'no data', store: item.storeId } );
1312
- }
1313
- const response = await axios.post( JSON.parse( process.env.URL ).zoneTaggingLamdaUrl, camDetails );
1314
- if ( response?.data?.status && response?.data?.status == 'success' ) {
1315
- let fileData = {
1316
- Key: `${req.body.storeId}/zonetagging/`,
1317
- fileName: `${req.body.storeId}_zonetagging.json`,
1318
- Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
1319
- body: JSON.stringify( camDetails ),
1320
- ContentType: 'application/json',
1321
- };
1322
- let upload = await fileUpload( fileData );
1323
- if ( !upload.Key ) {
1324
- logger.error( { message: `JSON Upload Error`, store: item.storeId } );
1325
- }
1326
- if ( index == 0 ) {
1327
- res.sendSuccess( 'Zone Updated Successfully' );
1310
+ if ( camDetails ) {
1311
+ const response = await axios.post( JSON.parse( process.env.URL ).zoneTaggingLamdaUrl, camDetails );
1312
+
1313
+ if ( response?.data?.status && response?.data?.status == 'success' ) {
1314
+ let fileData = {
1315
+ Key: `${req.body.storeId}/zonetagging/`,
1316
+ fileName: `${req.body.storeId}_zonetagging.json`,
1317
+ Bucket: JSON.parse( process.env.BUCKET ).zoneTaggingImage,
1318
+ body: JSON.stringify( camDetails ),
1319
+ ContentType: 'application/json',
1320
+ };
1321
+
1322
+ let upload = await fileUpload( fileData );
1323
+ if ( !upload.Key ) {
1324
+ logger.error( { message: `JSON Upload Error`, store: item.storeId } );
1325
+ }
1326
+ if ( index == 0 ) {
1327
+ res.sendSuccess( 'Zone Updated Successfully' );
1328
+ }
1329
+ } else {
1330
+ logger.error( { message: 'no data', store: item.storeId } );
1331
+ return res.sendError( 'something went wrong', 500 );
1328
1332
  }
1329
- } else {
1330
- logger.error( { message: 'no data', store: item.storeId } );
1331
- // return res.sendError( 'something went wrong', 500 );
1332
1333
  }
1333
1334
  }
1334
1335
  }
1335
1336
  } catch ( e ) {
1337
+ console.log( '🚀 ~ updateOldData ~ e:', e );
1336
1338
  logger.error( { error: e, function: 'updateOldData' } );
1337
1339
  return res.sendError( e, 500 );
1338
1340
  }
@@ -2113,8 +2115,14 @@ export const deleteZoneCustomTag = async ( req, res ) => {
2113
2115
  if ( !zoneTagDetails || zoneTagDetails?.length == 0 ) {
2114
2116
  return res.sendError( 'No data found', 400 );
2115
2117
  }
2116
-
2118
+ updateOldData( req, res );
2117
2119
  await customZoneTagService.deleteOne( { clientId, tagName } );
2120
+ await taggingService.deleteMany(
2121
+ {
2122
+ clientId,
2123
+ tagName: { $in: tagName },
2124
+ },
2125
+ );
2118
2126
  const logObj = {
2119
2127
  clientId: req.body?.clientId,
2120
2128
  userName: req.user?.userName,
@@ -2127,7 +2135,7 @@ export const deleteZoneCustomTag = async ( req, res ) => {
2127
2135
  showTo: [ 'client', 'tango' ],
2128
2136
  };
2129
2137
  insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
2130
- return res.sendSuccess( 'ZoneName Deleted Successfully' );
2138
+ // return res.sendSuccess( 'ZoneName Deleted Successfully' );
2131
2139
  } catch ( e ) {
2132
2140
  logger.error( { error: e, function: 'deleteZoneCustomTag' } );
2133
2141
  return res.sendError( e, 500 );
@@ -73,6 +73,39 @@ export async function bulkZoneExists( req, res, next ) {
73
73
  // }
74
74
  // }
75
75
 
76
+ // Validate groupNames for case-insensitive duplicates
77
+ const groupNameList = zonesArray
78
+ .filter( ( zone ) => zone.groupName && zone.groupName !== '' && zone.groupName !== null )
79
+ .map( ( zone ) => zone.groupName );
80
+
81
+ if ( groupNameList.length > 0 ) {
82
+ // Group groupNames by their lowercase version
83
+ const groupNameMap = new Map();
84
+ groupNameList.forEach( ( name ) => {
85
+ const lowerName = name.toLowerCase();
86
+ if ( !groupNameMap.has( lowerName ) ) {
87
+ groupNameMap.set( lowerName, new Set() );
88
+ }
89
+ groupNameMap.get( lowerName ).add( name );
90
+ } );
91
+
92
+ // Check if any lowercase name has multiple different cases
93
+ const caseMismatches = [];
94
+ groupNameMap.forEach( ( originalNames, lowerName ) => {
95
+ if ( originalNames.size > 1 ) {
96
+ // Same lowercase name appears with different cases
97
+ caseMismatches.push( {
98
+ lowerName: lowerName,
99
+ cases: Array.from( originalNames ),
100
+ } );
101
+ }
102
+ } );
103
+
104
+ if ( caseMismatches.length > 0 ) {
105
+ return res.sendError( 'Duplicate group names with different cases are not allowed.', 400 );
106
+ }
107
+ }
108
+
76
109
  // Attach clientId to req for use in controller
77
110
  req.bulkZoneClientId = clientId;
78
111
  next();