tango-app-api-store-zone 3.3.1-beta.24 → 3.3.1-beta.26
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
|
@@ -1307,6 +1307,7 @@ export const updateOldData = async ( req, res ) => {
|
|
|
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
|
+
console.log( '🚀 ~ updateOldData ~ camDetails:', camDetails );
|
|
1310
1311
|
if ( camDetails ) {
|
|
1311
1312
|
const response = await axios.post( JSON.parse( process.env.URL ).zoneTaggingLamdaUrl, camDetails );
|
|
1312
1313
|
|
|
@@ -1332,6 +1333,8 @@ export const updateOldData = async ( req, res ) => {
|
|
|
1332
1333
|
}
|
|
1333
1334
|
}
|
|
1334
1335
|
}
|
|
1336
|
+
} else {
|
|
1337
|
+
res.sendSuccess( 'Zone Updated Successfully' );
|
|
1335
1338
|
}
|
|
1336
1339
|
} catch ( e ) {
|
|
1337
1340
|
console.log( '🚀 ~ updateOldData ~ e:', e );
|
|
@@ -1802,33 +1805,61 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1802
1805
|
const zoneTagDataList = [];
|
|
1803
1806
|
const zoneGroupDataMap = new Map();
|
|
1804
1807
|
const createdTagNames = [];
|
|
1808
|
+
// Map to store user-provided groupName (any case) -> actual groupName from DB (preserving existing case)
|
|
1809
|
+
const groupNameMapping = new Map();
|
|
1810
|
+
|
|
1811
|
+
// First pass: Check for existing groups and create mapping
|
|
1812
|
+
const uniqueGroupNames = [ ...new Set( zonesArray.map( ( zone ) => zone.groupName ).filter( ( name ) => name && name !== '' && name !== null ) ) ];
|
|
1813
|
+
|
|
1814
|
+
for ( const userGroupName of uniqueGroupNames ) {
|
|
1815
|
+
// Case-insensitive check for existing group
|
|
1816
|
+
const existingGroupDoc = await customzonegrouping.findOne( {
|
|
1817
|
+
clientId,
|
|
1818
|
+
groupName: { $regex: `^${userGroupName}$`, $options: 'i' },
|
|
1819
|
+
} );
|
|
1820
|
+
|
|
1821
|
+
if ( existingGroupDoc ) {
|
|
1822
|
+
// Group exists - use the existing group's case
|
|
1823
|
+
groupNameMapping.set( userGroupName.toLowerCase(), existingGroupDoc.groupName );
|
|
1824
|
+
} else {
|
|
1825
|
+
// New group - use user-provided case
|
|
1826
|
+
groupNameMapping.set( userGroupName.toLowerCase(), userGroupName );
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1805
1829
|
|
|
1806
1830
|
// Process each zone in the array
|
|
1807
1831
|
for ( const zone of zonesArray ) {
|
|
1832
|
+
// Determine the correct groupName to use (existing case if group exists, user case if new)
|
|
1833
|
+
let normalizedGroupName = null;
|
|
1834
|
+
if ( zone.groupName && zone.groupName !== '' && zone.groupName !== null ) {
|
|
1835
|
+
normalizedGroupName = groupNameMapping.get( zone.groupName.toLowerCase() ) || zone.groupName;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1808
1838
|
const zoneTagData = {
|
|
1809
1839
|
clientId: clientId,
|
|
1810
1840
|
tagName: zone.tagName,
|
|
1811
1841
|
rgbColor: zone.rgbColor,
|
|
1812
1842
|
rgbBorderColor: zone.rgbBorderColor,
|
|
1813
|
-
groupName:
|
|
1843
|
+
groupName: normalizedGroupName,
|
|
1814
1844
|
productName: zone.productName,
|
|
1815
1845
|
};
|
|
1816
1846
|
zoneTagDataList.push( zoneTagData );
|
|
1817
1847
|
createdTagNames.push( zone.tagName );
|
|
1818
1848
|
|
|
1819
1849
|
// Prepare zone group data if groupName is provided
|
|
1820
|
-
if (
|
|
1821
|
-
|
|
1822
|
-
|
|
1850
|
+
if ( normalizedGroupName ) {
|
|
1851
|
+
// Use normalized groupName (existing case or user case)
|
|
1852
|
+
if ( !zoneGroupDataMap.has( normalizedGroupName ) ) {
|
|
1853
|
+
zoneGroupDataMap.set( normalizedGroupName, {
|
|
1823
1854
|
clientId: clientId,
|
|
1824
|
-
groupName:
|
|
1855
|
+
groupName: normalizedGroupName,
|
|
1825
1856
|
productName: zone.productName,
|
|
1826
1857
|
zonesTagged: new Set(),
|
|
1827
1858
|
} );
|
|
1828
1859
|
}
|
|
1829
1860
|
|
|
1830
1861
|
// Collect all tagNames for this group so that we can append them
|
|
1831
|
-
const groupEntry = zoneGroupDataMap.get(
|
|
1862
|
+
const groupEntry = zoneGroupDataMap.get( normalizedGroupName );
|
|
1832
1863
|
groupEntry.zonesTagged.add( zone.tagName );
|
|
1833
1864
|
}
|
|
1834
1865
|
}
|
|
@@ -1880,11 +1911,13 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1880
1911
|
}
|
|
1881
1912
|
|
|
1882
1913
|
// Ensure tagging documents are also mapped to the correct groupName for newly uploaded zones
|
|
1914
|
+
// Use normalized groupName (existing case if group exists, user case if new)
|
|
1883
1915
|
for ( const zone of zonesArray ) {
|
|
1884
1916
|
if ( zone.groupName && zone.groupName !== '' && zone.groupName !== null ) {
|
|
1917
|
+
const normalizedGroupName = groupNameMapping.get( zone.groupName.toLowerCase() ) || zone.groupName;
|
|
1885
1918
|
await taggingService.updateMany(
|
|
1886
1919
|
{ clientId, tagName: zone.tagName },
|
|
1887
|
-
{ $set: { groupName:
|
|
1920
|
+
{ $set: { groupName: normalizedGroupName } },
|
|
1888
1921
|
);
|
|
1889
1922
|
}
|
|
1890
1923
|
}
|
|
@@ -2265,7 +2298,7 @@ export const getZoneGroupDetails = async ( req, res ) => {
|
|
|
2265
2298
|
'Zones tagged': Array.isArray( element.zonesTagged ) ?
|
|
2266
2299
|
element.zonesTagged.map( ( zone ) => zone.tagName ).filter( Boolean ).
|
|
2267
2300
|
join( ', ' ) : '--',
|
|
2268
|
-
'Zones tagged Count': element.
|
|
2301
|
+
'Zones tagged Count': element.zonesTagged.length || 0,
|
|
2269
2302
|
} ) );
|
|
2270
2303
|
await download( exportdata, res );
|
|
2271
2304
|
return;
|
|
@@ -24,7 +24,7 @@ export async function bulkZoneExists( req, res, next ) {
|
|
|
24
24
|
}
|
|
25
25
|
const clientId = uniqueClientIds[0];
|
|
26
26
|
|
|
27
|
-
// Check for duplicate tagNames within the request
|
|
27
|
+
// Check for duplicate tagNames within the request
|
|
28
28
|
const tagNameList = zonesArray.map( ( zone ) => zone.tagName );
|
|
29
29
|
const tagNameListLower = tagNameList.map( ( name ) => name.toLowerCase() );
|
|
30
30
|
const uniqueTagNamesLower = [ ...new Set( tagNameListLower ) ];
|
|
@@ -32,8 +32,7 @@ export async function bulkZoneExists( req, res, next ) {
|
|
|
32
32
|
return res.sendError( `Duplicate zone name found in request.`, 400 );
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
// Fetch all existing tags for this client and compare case-insensitively
|
|
35
|
+
// Fetch all existing tags for this client and compare
|
|
37
36
|
const existingZones = await customZoneTagService.find( {
|
|
38
37
|
clientId: clientId,
|
|
39
38
|
} );
|
|
@@ -46,66 +45,6 @@ export async function bulkZoneExists( req, res, next ) {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
// Check for duplicate groupNames within the request (case-insensitive, if provided)
|
|
50
|
-
// const groupNameList = zonesArray
|
|
51
|
-
// .filter( ( zone ) => zone.groupName && zone.groupName !== '' && zone.groupName !== null )
|
|
52
|
-
// .map( ( zone ) => zone.groupName );
|
|
53
|
-
|
|
54
|
-
// if ( groupNameList.length > 0 ) {
|
|
55
|
-
// const groupNameListLower = groupNameList.map( ( name ) => name.toLowerCase() );
|
|
56
|
-
// const uniqueGroupNamesLower = [ ...new Set( groupNameListLower ) ];
|
|
57
|
-
// if ( uniqueGroupNamesLower.length !== groupNameListLower.length ) {
|
|
58
|
-
// return res.sendError( `Duplicate group names found in request.`, 400 );
|
|
59
|
-
// }
|
|
60
|
-
|
|
61
|
-
// // Check if any groupNames already exist in the database for this client (case-insensitive)
|
|
62
|
-
// // Fetch all existing groups for this client and compare case-insensitively
|
|
63
|
-
// const existingGroups = await customzonegrouping.find( {
|
|
64
|
-
// clientId: clientId,
|
|
65
|
-
// } );
|
|
66
|
-
|
|
67
|
-
// if ( existingGroups && existingGroups.length > 0 ) {
|
|
68
|
-
// const existingGroupNamesLower = existingGroups.map( ( group ) => group.groupName?.toLowerCase() ).filter( Boolean );
|
|
69
|
-
// const hasDuplicate = groupNameListLower.some( ( groupNameLower ) => existingGroupNamesLower.includes( groupNameLower ) );
|
|
70
|
-
// if ( hasDuplicate ) {
|
|
71
|
-
// return res.sendError( `Group names already exist for this client.`, 409 );
|
|
72
|
-
// }
|
|
73
|
-
// }
|
|
74
|
-
// }
|
|
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
|
-
|
|
109
48
|
// Attach clientId to req for use in controller
|
|
110
49
|
req.bulkZoneClientId = clientId;
|
|
111
50
|
next();
|