tango-app-api-store-zone 3.3.1-beta.20 → 3.3.1-beta.22
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
|
@@ -544,6 +544,11 @@ export const customTagListv3 = async ( req, res ) => {
|
|
|
544
544
|
count: 1,
|
|
545
545
|
},
|
|
546
546
|
},
|
|
547
|
+
{
|
|
548
|
+
$sort: {
|
|
549
|
+
count: -1,
|
|
550
|
+
},
|
|
551
|
+
},
|
|
547
552
|
|
|
548
553
|
// Split grouped vs ungrouped
|
|
549
554
|
{
|
|
@@ -1508,7 +1513,6 @@ export const getZoneTaggingDetails = async ( req, res ) => {
|
|
|
1508
1513
|
|
|
1509
1514
|
const pipeline = [
|
|
1510
1515
|
{ $match: matchStage },
|
|
1511
|
-
|
|
1512
1516
|
{
|
|
1513
1517
|
$lookup: {
|
|
1514
1518
|
from: 'taggings',
|
|
@@ -1520,15 +1524,21 @@ export const getZoneTaggingDetails = async ( req, res ) => {
|
|
|
1520
1524
|
$and: [
|
|
1521
1525
|
{ $eq: [ '$tagName', '$$tagName' ] },
|
|
1522
1526
|
{ $eq: [ '$clientId', clientId ] },
|
|
1527
|
+
{ $ne: [ '$coordinates', [] ] },
|
|
1523
1528
|
],
|
|
1524
1529
|
},
|
|
1525
1530
|
},
|
|
1526
1531
|
},
|
|
1532
|
+
{
|
|
1533
|
+
$group: {
|
|
1534
|
+
_id: '$storeId',
|
|
1535
|
+
count: { $sum: 1 },
|
|
1536
|
+
},
|
|
1537
|
+
},
|
|
1527
1538
|
],
|
|
1528
1539
|
as: 'tagsCount',
|
|
1529
1540
|
},
|
|
1530
1541
|
},
|
|
1531
|
-
|
|
1532
1542
|
{
|
|
1533
1543
|
$project: {
|
|
1534
1544
|
clientId: 1,
|
|
@@ -1537,7 +1547,6 @@ export const getZoneTaggingDetails = async ( req, res ) => {
|
|
|
1537
1547
|
storesTaggedCount: { $size: '$tagsCount' },
|
|
1538
1548
|
},
|
|
1539
1549
|
},
|
|
1540
|
-
|
|
1541
1550
|
{
|
|
1542
1551
|
$facet: {
|
|
1543
1552
|
totalCount: [
|
|
@@ -1692,20 +1701,22 @@ export const addZoneCustomTag = async ( req, res ) => {
|
|
|
1692
1701
|
} = req.body;
|
|
1693
1702
|
|
|
1694
1703
|
if ( !clientId || !tagName ) {
|
|
1695
|
-
return res.sendError( 'clientId and
|
|
1704
|
+
return res.sendError( 'clientId and zoneName are required', 400 );
|
|
1696
1705
|
}
|
|
1697
1706
|
|
|
1707
|
+
// Case-insensitive check for existing tag
|
|
1698
1708
|
const existingTag = await customZoneTagService.findOne(
|
|
1699
|
-
{ clientId, tagName, _id: { $ne: _id } },
|
|
1709
|
+
{ clientId, tagName: { $regex: `^${tagName}$`, $options: 'i' }, _id: { $ne: _id } },
|
|
1700
1710
|
);
|
|
1701
1711
|
|
|
1702
1712
|
if ( existingTag ) {
|
|
1703
|
-
return res.sendError( `
|
|
1713
|
+
return res.sendError( `zoneName "${tagName}" already exists for this client`, 409 );
|
|
1704
1714
|
}
|
|
1705
1715
|
|
|
1706
1716
|
let groupDoc = null;
|
|
1707
1717
|
if ( groupName ) {
|
|
1708
|
-
|
|
1718
|
+
// Case-insensitive check for existing group
|
|
1719
|
+
groupDoc = await customzonegrouping.findOne( { clientId, groupName: { $regex: `^${groupName}$`, $options: 'i' } } );
|
|
1709
1720
|
}
|
|
1710
1721
|
|
|
1711
1722
|
if ( !isExistingGroup && groupDoc ) {
|
|
@@ -1803,8 +1814,13 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1803
1814
|
clientId: clientId,
|
|
1804
1815
|
groupName: zone.groupName,
|
|
1805
1816
|
productName: zone.productName,
|
|
1817
|
+
zonesTagged: new Set(),
|
|
1806
1818
|
} );
|
|
1807
1819
|
}
|
|
1820
|
+
|
|
1821
|
+
// Collect all tagNames for this group so that we can append them
|
|
1822
|
+
const groupEntry = zoneGroupDataMap.get( zone.groupName );
|
|
1823
|
+
groupEntry.zonesTagged.add( zone.tagName );
|
|
1808
1824
|
}
|
|
1809
1825
|
}
|
|
1810
1826
|
|
|
@@ -1812,13 +1828,59 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1812
1828
|
await customZoneTagService.create( zoneTagDataList );
|
|
1813
1829
|
|
|
1814
1830
|
// Create zone groups (convert Map values to array)
|
|
1815
|
-
const zoneGroupDataList = Array.from( zoneGroupDataMap.values() );
|
|
1831
|
+
// const zoneGroupDataList = Array.from( zoneGroupDataMap.values() );
|
|
1832
|
+
// console.log( 'zoneGroupDataList', zoneGroupDataList );
|
|
1833
|
+
// if ( zoneGroupDataList.length > 0 ) {
|
|
1834
|
+
// for ( const groupData of zoneGroupDataList ) {
|
|
1835
|
+
// await customzonegrouping.create( groupData );
|
|
1836
|
+
// }
|
|
1837
|
+
// }
|
|
1838
|
+
|
|
1839
|
+
// Create or Update Zone Groups (following addZoneCustomTag pattern)
|
|
1840
|
+
const zoneGroupDataList = Array.from( zoneGroupDataMap.values() ).map( ( groupData ) => ( {
|
|
1841
|
+
clientId: groupData.clientId,
|
|
1842
|
+
groupName: groupData.groupName,
|
|
1843
|
+
productName: groupData.productName,
|
|
1844
|
+
zonesTagged: Array.from( groupData.zonesTagged || [] ),
|
|
1845
|
+
} ) );
|
|
1846
|
+
|
|
1816
1847
|
if ( zoneGroupDataList.length > 0 ) {
|
|
1817
1848
|
for ( const groupData of zoneGroupDataList ) {
|
|
1818
|
-
|
|
1849
|
+
// Case-insensitive check for existing group (same as addZoneCustomTag)
|
|
1850
|
+
const groupDoc = await customzonegrouping.findOne( {
|
|
1851
|
+
clientId,
|
|
1852
|
+
groupName: { $regex: `^${groupData.groupName}$`, $options: 'i' },
|
|
1853
|
+
} );
|
|
1854
|
+
|
|
1855
|
+
if ( !groupDoc ) {
|
|
1856
|
+
// Create new group with all zones from the bulk file
|
|
1857
|
+
await customzonegrouping.create( [ {
|
|
1858
|
+
clientId: groupData.clientId,
|
|
1859
|
+
groupName: groupData.groupName,
|
|
1860
|
+
productName: groupData.productName,
|
|
1861
|
+
zonesTagged: groupData.zonesTagged,
|
|
1862
|
+
} ] );
|
|
1863
|
+
} else {
|
|
1864
|
+
// Group exists - add new zones to existing zonesTagged array (preserving existing mappings)
|
|
1865
|
+
await customzonegrouping.updateOne(
|
|
1866
|
+
{ _id: groupDoc._id },
|
|
1867
|
+
{ $addToSet: { zonesTagged: { $each: groupData.zonesTagged } } },
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1819
1870
|
}
|
|
1820
1871
|
}
|
|
1821
1872
|
|
|
1873
|
+
// Ensure tagging documents are also mapped to the correct groupName for newly uploaded zones
|
|
1874
|
+
for ( const zone of zonesArray ) {
|
|
1875
|
+
if ( zone.groupName && zone.groupName !== '' && zone.groupName !== null ) {
|
|
1876
|
+
await taggingService.updateMany(
|
|
1877
|
+
{ clientId, tagName: zone.tagName },
|
|
1878
|
+
{ $set: { groupName: zone.groupName } },
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
|
|
1822
1884
|
logger.info( `Bulk Zone Tags Created Successfully: ${createdTagNames.length} tags` );
|
|
1823
1885
|
const logObj = {
|
|
1824
1886
|
clientId: clientId,
|
|
@@ -1847,19 +1909,19 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1847
1909
|
const { clientId, tagName, oldTag, isExistingGroup, oldGroupName, groupName } = req.body;
|
|
1848
1910
|
|
|
1849
1911
|
if ( !clientId || !tagName ) {
|
|
1850
|
-
return res.sendError( 'clientId,
|
|
1912
|
+
return res.sendError( 'clientId, zoneName are required', 400 );
|
|
1851
1913
|
}
|
|
1852
1914
|
|
|
1853
1915
|
let findQuery = {};
|
|
1854
1916
|
if ( oldTag !== undefined && oldTag !== null && tagName !== oldTag ) {
|
|
1855
1917
|
findQuery = {
|
|
1856
1918
|
clientId,
|
|
1857
|
-
tagName: oldTag,
|
|
1919
|
+
tagName: { $regex: `^${oldTag}$`, $options: 'i' },
|
|
1858
1920
|
};
|
|
1859
1921
|
} else {
|
|
1860
1922
|
findQuery = {
|
|
1861
1923
|
clientId,
|
|
1862
|
-
tagName,
|
|
1924
|
+
tagName: { $regex: `^${tagName}$`, $options: 'i' },
|
|
1863
1925
|
};
|
|
1864
1926
|
}
|
|
1865
1927
|
|
|
@@ -1874,19 +1936,19 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1874
1936
|
// Get the actual tag name currently in the database
|
|
1875
1937
|
const actualTagNameInDb = customZoneTagDetails.tagName;
|
|
1876
1938
|
|
|
1877
|
-
// Validate that the new tagName does not already exist for this client
|
|
1939
|
+
// Validate that the new tagName does not already exist for this client (case-insensitive)
|
|
1878
1940
|
// Check if tagName is being changed (either via oldTag or if it's different from DB value)
|
|
1879
|
-
const isTagNameChanging = ( oldTag && tagName !== oldTag ) || ( actualTagNameInDb && tagName !== actualTagNameInDb );
|
|
1941
|
+
const isTagNameChanging = ( oldTag && tagName.toLowerCase() !== oldTag.toLowerCase() ) || ( actualTagNameInDb && tagName.toLowerCase() !== actualTagNameInDb.toLowerCase() );
|
|
1880
1942
|
|
|
1881
1943
|
if ( isTagNameChanging ) {
|
|
1882
1944
|
const existingTagWithNewName = await customZoneTagService.findOne( {
|
|
1883
1945
|
clientId,
|
|
1884
|
-
tagName,
|
|
1946
|
+
tagName: { $regex: `^${tagName}$`, $options: 'i' },
|
|
1885
1947
|
} );
|
|
1886
1948
|
|
|
1887
1949
|
// If a tag with the new name exists and it's not the same record we're updating, return error
|
|
1888
1950
|
if ( existingTagWithNewName && existingTagWithNewName._id.toString() !== customZoneTagDetails._id.toString() ) {
|
|
1889
|
-
return res.sendError( `
|
|
1951
|
+
return res.sendError( `zoneName "${tagName}" already exists for this client`, 409 );
|
|
1890
1952
|
}
|
|
1891
1953
|
}
|
|
1892
1954
|
|
|
@@ -1911,15 +1973,15 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1911
1973
|
const newTagNameForGroup = tagName;
|
|
1912
1974
|
|
|
1913
1975
|
// Handle group changes: remove from old group and add to new group
|
|
1914
|
-
// Compare actual old group name from DB with new group name
|
|
1915
|
-
const oldGroupNameStr = actualOldGroupName ? String( actualOldGroupName ).trim() : null;
|
|
1916
|
-
const newGroupNameStr = groupName ? String( groupName ).trim() : null;
|
|
1976
|
+
// Compare actual old group name from DB with new group name (case-insensitive)
|
|
1977
|
+
const oldGroupNameStr = actualOldGroupName ? String( actualOldGroupName ).trim().toLowerCase() : null;
|
|
1978
|
+
const newGroupNameStr = groupName ? String( groupName ).trim().toLowerCase() : null;
|
|
1917
1979
|
|
|
1918
1980
|
if ( oldGroupNameStr !== newGroupNameStr ) {
|
|
1919
1981
|
// Remove tag from old group if oldGroupName exists
|
|
1920
1982
|
if ( actualOldGroupName ) {
|
|
1921
1983
|
const oldGroupDoc = await customzonegrouping.findOne(
|
|
1922
|
-
{ clientId, groupName: actualOldGroupName },
|
|
1984
|
+
{ clientId, groupName: { $regex: `^${actualOldGroupName}$`, $options: 'i' } },
|
|
1923
1985
|
);
|
|
1924
1986
|
if ( oldGroupDoc ) {
|
|
1925
1987
|
await customzonegrouping.updateOne(
|
|
@@ -1933,7 +1995,7 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1933
1995
|
// Add tag to new group if groupName exists
|
|
1934
1996
|
if ( groupName ) {
|
|
1935
1997
|
let newGroupDoc = await customzonegrouping.findOne(
|
|
1936
|
-
{ clientId, groupName },
|
|
1998
|
+
{ clientId, groupName: { $regex: `^${groupName}$`, $options: 'i' } },
|
|
1937
1999
|
);
|
|
1938
2000
|
|
|
1939
2001
|
if ( !newGroupDoc && !isExistingGroup ) {
|
|
@@ -1955,7 +2017,8 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1955
2017
|
}
|
|
1956
2018
|
} else if ( groupName && oldGroupNameStr === newGroupNameStr && oldTag && tagName !== oldTag ) {
|
|
1957
2019
|
// If groupName is same (and not null) but tagName changed, update the tagName in the group's zonesTagged
|
|
1958
|
-
|
|
2020
|
+
console.log( 'Group name same but tagName changed, updating group zonesTagged' );
|
|
2021
|
+
const groupDoc = await customzonegrouping.findOne( { clientId, groupName: { $regex: `^${groupName}$`, $options: 'i' } } );
|
|
1959
2022
|
if ( groupDoc ) {
|
|
1960
2023
|
await customzonegrouping.updateOne(
|
|
1961
2024
|
{ _id: groupDoc._id },
|
|
@@ -2002,7 +2065,7 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
2002
2065
|
date: new Date(),
|
|
2003
2066
|
logType: 'zone',
|
|
2004
2067
|
logSubType: 'updateZoneCustomTag',
|
|
2005
|
-
changes: [ `
|
|
2068
|
+
changes: [ `zoneName changed from ${oldTag} to ${tagName}` ],
|
|
2006
2069
|
eventType: 'update',
|
|
2007
2070
|
previous: {
|
|
2008
2071
|
tagName: oldTag,
|
|
@@ -2020,8 +2083,8 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
2020
2083
|
};
|
|
2021
2084
|
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
2022
2085
|
if ( zonetag.modifiedCount || zonetag.matchedCount ) {
|
|
2023
|
-
logger.info( '
|
|
2024
|
-
res.sendSuccess( '
|
|
2086
|
+
logger.info( 'ZoneName Updated Successfully' );
|
|
2087
|
+
res.sendSuccess( 'ZoneName Updated Successfully' );
|
|
2025
2088
|
} else {
|
|
2026
2089
|
logger.error( { error: 'something went wrong', function: 'updateZoneCustomTag' } );
|
|
2027
2090
|
return res.sendError( 'something went wrong', 500 );
|
|
@@ -2036,7 +2099,7 @@ export const deleteZoneCustomTag = async ( req, res ) => {
|
|
|
2036
2099
|
try {
|
|
2037
2100
|
const { clientId, tagName } = req.body;
|
|
2038
2101
|
if ( !clientId || !tagName ) {
|
|
2039
|
-
return res.sendError( 'clientId and
|
|
2102
|
+
return res.sendError( 'clientId and zoneName are required', 400 );
|
|
2040
2103
|
}
|
|
2041
2104
|
|
|
2042
2105
|
let zoneTagDetails = await customZoneTagService.findOne( { clientId, tagName } );
|
|
@@ -2057,7 +2120,7 @@ export const deleteZoneCustomTag = async ( req, res ) => {
|
|
|
2057
2120
|
showTo: [ 'client', 'tango' ],
|
|
2058
2121
|
};
|
|
2059
2122
|
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
2060
|
-
return res.sendSuccess( '
|
|
2123
|
+
return res.sendSuccess( 'ZoneName Deleted Successfully' );
|
|
2061
2124
|
} catch ( e ) {
|
|
2062
2125
|
logger.error( { error: e, function: 'deleteZoneCustomTag' } );
|
|
2063
2126
|
return res.sendError( e, 500 );
|
|
@@ -2333,6 +2396,16 @@ export const addZoneGroup = async ( req, res ) => {
|
|
|
2333
2396
|
return res.sendError( 'clientId and groupName are required', 400 );
|
|
2334
2397
|
}
|
|
2335
2398
|
|
|
2399
|
+
// Case-insensitive check for existing group
|
|
2400
|
+
const existingGroup = await customzonegrouping.findOne( {
|
|
2401
|
+
clientId,
|
|
2402
|
+
groupName: { $regex: `^${groupName}$`, $options: 'i' },
|
|
2403
|
+
} );
|
|
2404
|
+
|
|
2405
|
+
if ( existingGroup ) {
|
|
2406
|
+
return res.sendError( `groupName "${groupName}" already exists for this client`, 409 );
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2336
2409
|
const payload = {
|
|
2337
2410
|
clientId,
|
|
2338
2411
|
groupName,
|
|
@@ -2397,13 +2470,14 @@ export const updateZoneGroup = async ( req, res ) => {
|
|
|
2397
2470
|
}
|
|
2398
2471
|
|
|
2399
2472
|
let findGroup = await customzonegrouping.findOne( { _id: _id } );
|
|
2473
|
+
// Case-insensitive check for existing group (excluding current group)
|
|
2400
2474
|
const existingGroup = await customzonegrouping.findOne( {
|
|
2401
2475
|
clientId: clientId,
|
|
2402
|
-
groupName: groupName,
|
|
2476
|
+
groupName: { $regex: `^${groupName}$`, $options: 'i' },
|
|
2403
2477
|
_id: { $ne: _id },
|
|
2404
2478
|
} );
|
|
2405
2479
|
if ( existingGroup && existingGroup.groupName ) {
|
|
2406
|
-
return res.sendError( `groupName "${
|
|
2480
|
+
return res.sendError( `groupName "${groupName}" already exists for this client`, 409 );
|
|
2407
2481
|
}
|
|
2408
2482
|
|
|
2409
2483
|
if ( findGroup ) {
|
|
@@ -24,49 +24,55 @@ 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 (case-insensitive)
|
|
28
28
|
const tagNameList = zonesArray.map( ( zone ) => zone.tagName );
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const tagNameListLower = tagNameList.map( ( name ) => name.toLowerCase() );
|
|
30
|
+
const uniqueTagNamesLower = [ ...new Set( tagNameListLower ) ];
|
|
31
|
+
if ( uniqueTagNamesLower.length !== tagNameListLower.length ) {
|
|
32
32
|
return res.sendError( `Duplicate zone name found in request.`, 400 );
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
// Check if any tagNames already exist in the database for this client
|
|
35
|
+
// Check if any tagNames already exist in the database for this client (case-insensitive)
|
|
36
|
+
// Fetch all existing tags for this client and compare case-insensitively
|
|
36
37
|
const existingZones = await customZoneTagService.find( {
|
|
37
38
|
clientId: clientId,
|
|
38
|
-
tagName: { $in: tagNameList },
|
|
39
39
|
} );
|
|
40
40
|
|
|
41
41
|
if ( existingZones && existingZones.length > 0 ) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Check for duplicate groupNames within the request (if provided)
|
|
47
|
-
const groupNameList = zonesArray
|
|
48
|
-
.filter( ( zone ) => zone.groupName && zone.groupName !== '' && zone.groupName !== null )
|
|
49
|
-
.map( ( zone ) => zone.groupName );
|
|
50
|
-
|
|
51
|
-
if ( groupNameList.length > 0 ) {
|
|
52
|
-
const uniqueGroupNames = [ ...new Set( groupNameList ) ];
|
|
53
|
-
if ( uniqueGroupNames.length !== groupNameList.length ) {
|
|
54
|
-
// const duplicateGroups = groupNameList.filter( ( groupName, index ) => groupNameList.indexOf( groupName ) !== index );
|
|
55
|
-
return res.sendError( `Duplicate group names found in request.`, 400 );
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Check if any groupNames already exist in the database for this client
|
|
59
|
-
const existingGroups = await customzonegrouping.find( {
|
|
60
|
-
clientId: clientId,
|
|
61
|
-
groupName: { $in: uniqueGroupNames },
|
|
62
|
-
} );
|
|
63
|
-
|
|
64
|
-
if ( existingGroups && existingGroups.length > 0 ) {
|
|
65
|
-
// const existingGroupNames = existingGroups.map( ( group ) => group.groupName );
|
|
66
|
-
return res.sendError( `Group names already exist for this client.`, 409 );
|
|
42
|
+
const existingTagNamesLower = existingZones.map( ( zone ) => zone.tagName?.toLowerCase() ).filter( Boolean );
|
|
43
|
+
const hasDuplicate = tagNameListLower.some( ( tagNameLower ) => existingTagNamesLower.includes( tagNameLower ) );
|
|
44
|
+
if ( hasDuplicate ) {
|
|
45
|
+
return res.sendError( `Zone names already exist for this client.`, 409 );
|
|
67
46
|
}
|
|
68
47
|
}
|
|
69
48
|
|
|
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
|
+
|
|
70
76
|
// Attach clientId to req for use in controller
|
|
71
77
|
req.bulkZoneClientId = clientId;
|
|
72
78
|
next();
|
|
@@ -99,21 +105,26 @@ export async function bulkZoneGroupExists( req, res, next ) {
|
|
|
99
105
|
}
|
|
100
106
|
const clientId = uniqueClientIds[0];
|
|
101
107
|
|
|
102
|
-
// Check for duplicate groupNames within the request
|
|
108
|
+
// Check for duplicate groupNames within the request (case-insensitive)
|
|
103
109
|
const groupNameList = groupsArray.map( ( group ) => group.groupName );
|
|
104
|
-
const
|
|
105
|
-
|
|
110
|
+
const groupNameListLower = groupNameList.map( ( name ) => name.toLowerCase() );
|
|
111
|
+
const uniqueGroupNamesLower = [ ...new Set( groupNameListLower ) ];
|
|
112
|
+
if ( uniqueGroupNamesLower.length !== groupNameListLower.length ) {
|
|
106
113
|
return res.sendError( `Duplicate group names found in request.`, 400 );
|
|
107
114
|
}
|
|
108
115
|
|
|
109
|
-
// Check if any groupNames already exist in the database for this client
|
|
116
|
+
// Check if any groupNames already exist in the database for this client (case-insensitive)
|
|
117
|
+
// Fetch all existing groups for this client and compare case-insensitively
|
|
110
118
|
const existingGroups = await customzonegrouping.find( {
|
|
111
119
|
clientId: clientId,
|
|
112
|
-
groupName: { $in: uniqueGroupNames },
|
|
113
120
|
} );
|
|
114
121
|
|
|
115
122
|
if ( existingGroups && existingGroups.length > 0 ) {
|
|
116
|
-
|
|
123
|
+
const existingGroupNamesLower = existingGroups.map( ( group ) => group.groupName?.toLowerCase() ).filter( Boolean );
|
|
124
|
+
const hasDuplicate = groupNameListLower.some( ( groupNameLower ) => existingGroupNamesLower.includes( groupNameLower ) );
|
|
125
|
+
if ( hasDuplicate ) {
|
|
126
|
+
return res.sendError( `Group names already exist for this client.`, 409 );
|
|
127
|
+
}
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
// Attach clientId to req for use in controller
|