tango-app-api-store-zone 3.3.1-beta.26 → 3.3.1-beta.29
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
|
@@ -1303,6 +1303,7 @@ export const updateOldData = async ( req, res ) => {
|
|
|
1303
1303
|
try {
|
|
1304
1304
|
let tagDetails = await taggingService.find( { clientId: req.body.clientId, tagName: req.body.tagName }, { storeId: 1 } );
|
|
1305
1305
|
|
|
1306
|
+
|
|
1306
1307
|
if ( tagDetails.length ) {
|
|
1307
1308
|
for ( let [ index, item ] of tagDetails.entries() ) {
|
|
1308
1309
|
req.body.storeId = item.storeId;
|
|
@@ -1324,14 +1325,14 @@ export const updateOldData = async ( req, res ) => {
|
|
|
1324
1325
|
if ( !upload.Key ) {
|
|
1325
1326
|
logger.error( { message: `JSON Upload Error`, store: item.storeId } );
|
|
1326
1327
|
}
|
|
1327
|
-
if ( index == 0 ) {
|
|
1328
|
-
res.sendSuccess( 'Zone Updated Successfully' );
|
|
1329
|
-
}
|
|
1330
1328
|
} else {
|
|
1331
1329
|
logger.error( { message: 'no data', store: item.storeId } );
|
|
1332
1330
|
return res.sendError( 'something went wrong', 500 );
|
|
1333
1331
|
}
|
|
1334
1332
|
}
|
|
1333
|
+
if ( index == tagDetails.length-1 ) {
|
|
1334
|
+
res.sendSuccess( 'Zone Updated Successfully' );
|
|
1335
|
+
}
|
|
1335
1336
|
}
|
|
1336
1337
|
} else {
|
|
1337
1338
|
res.sendSuccess( 'Zone Updated Successfully' );
|
|
@@ -1494,7 +1495,7 @@ export const getZoneTaggingDetails = async ( req, res ) => {
|
|
|
1494
1495
|
searchValue,
|
|
1495
1496
|
sortColumName,
|
|
1496
1497
|
sortBy,
|
|
1497
|
-
limit
|
|
1498
|
+
limit,
|
|
1498
1499
|
offset = 1,
|
|
1499
1500
|
export: isExport,
|
|
1500
1501
|
} = req.body;
|
|
@@ -1570,10 +1571,10 @@ export const getZoneTaggingDetails = async ( req, res ) => {
|
|
|
1570
1571
|
[] ),
|
|
1571
1572
|
...( isExport ?
|
|
1572
1573
|
[] :
|
|
1573
|
-
[
|
|
1574
|
+
limit ? [
|
|
1574
1575
|
{ $skip: ( offset - 1 ) * limit },
|
|
1575
1576
|
{ $limit: Number( limit ) },
|
|
1576
|
-
] ),
|
|
1577
|
+
] : [] ),
|
|
1577
1578
|
],
|
|
1578
1579
|
},
|
|
1579
1580
|
},
|
|
@@ -1716,9 +1717,12 @@ export const addZoneCustomTag = async ( req, res ) => {
|
|
|
1716
1717
|
return res.sendError( 'clientId and zoneName are required', 400 );
|
|
1717
1718
|
}
|
|
1718
1719
|
|
|
1720
|
+
// Escape regex special characters in tagName to avoid invalid regex patterns
|
|
1721
|
+
const escapedTagName = tagName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
1722
|
+
|
|
1719
1723
|
// Case-insensitive check for existing tag
|
|
1720
1724
|
const existingTag = await customZoneTagService.findOne(
|
|
1721
|
-
{ clientId, tagName: { $regex: `^${
|
|
1725
|
+
{ clientId, tagName: { $regex: `^${escapedTagName}$`, $options: 'i' }, _id: { $ne: _id } },
|
|
1722
1726
|
);
|
|
1723
1727
|
|
|
1724
1728
|
if ( existingTag ) {
|
|
@@ -1727,8 +1731,10 @@ export const addZoneCustomTag = async ( req, res ) => {
|
|
|
1727
1731
|
|
|
1728
1732
|
let groupDoc = null;
|
|
1729
1733
|
if ( groupName ) {
|
|
1734
|
+
// Escape regex special characters in groupName to avoid invalid regex patterns
|
|
1735
|
+
const escapedGroupName = groupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
1730
1736
|
// Case-insensitive check for existing group
|
|
1731
|
-
groupDoc = await customzonegrouping.findOne( { clientId, groupName: { $regex: `^${
|
|
1737
|
+
groupDoc = await customzonegrouping.findOne( { clientId, groupName: { $regex: `^${escapedGroupName}$`, $options: 'i' } } );
|
|
1732
1738
|
}
|
|
1733
1739
|
|
|
1734
1740
|
if ( !isExistingGroup && groupDoc ) {
|
|
@@ -1812,10 +1818,13 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1812
1818
|
const uniqueGroupNames = [ ...new Set( zonesArray.map( ( zone ) => zone.groupName ).filter( ( name ) => name && name !== '' && name !== null ) ) ];
|
|
1813
1819
|
|
|
1814
1820
|
for ( const userGroupName of uniqueGroupNames ) {
|
|
1821
|
+
// Escape regex special characters in group name to avoid invalid regex patterns
|
|
1822
|
+
const escapedUserGroupName = userGroupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
1823
|
+
|
|
1815
1824
|
// Case-insensitive check for existing group
|
|
1816
1825
|
const existingGroupDoc = await customzonegrouping.findOne( {
|
|
1817
1826
|
clientId,
|
|
1818
|
-
groupName: { $regex: `^${
|
|
1827
|
+
groupName: { $regex: `^${escapedUserGroupName}$`, $options: 'i' },
|
|
1819
1828
|
} );
|
|
1820
1829
|
|
|
1821
1830
|
if ( existingGroupDoc ) {
|
|
@@ -1887,9 +1896,10 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1887
1896
|
if ( zoneGroupDataList.length > 0 ) {
|
|
1888
1897
|
for ( const groupData of zoneGroupDataList ) {
|
|
1889
1898
|
// Case-insensitive check for existing group (same as addZoneCustomTag)
|
|
1899
|
+
const escapedGroupName = groupData.groupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
1890
1900
|
const groupDoc = await customzonegrouping.findOne( {
|
|
1891
1901
|
clientId,
|
|
1892
|
-
groupName: { $regex: `^${
|
|
1902
|
+
groupName: { $regex: `^${escapedGroupName}$`, $options: 'i' },
|
|
1893
1903
|
} );
|
|
1894
1904
|
|
|
1895
1905
|
if ( !groupDoc ) {
|
|
@@ -1941,6 +1951,7 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1941
1951
|
count: createdTagNames.length,
|
|
1942
1952
|
} );
|
|
1943
1953
|
} catch ( e ) {
|
|
1954
|
+
console.log( 'uploadBulkZoneTags error :', e );
|
|
1944
1955
|
logger.error( { error: e, function: 'addBulkZoneCustomTag' } );
|
|
1945
1956
|
return res.sendError( 'Failed to upload zone-config file', 500 );
|
|
1946
1957
|
}
|
|
@@ -1955,18 +1966,23 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1955
1966
|
}
|
|
1956
1967
|
|
|
1957
1968
|
let findQuery = {};
|
|
1969
|
+
|
|
1970
|
+
// Escape regex special characters in tag names to avoid invalid regex patterns
|
|
1971
|
+
const escapedTagName = tagName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
1972
|
+
const escapedOldTag = oldTag ? oldTag.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ) : null;
|
|
1958
1973
|
if ( oldTag !== undefined && oldTag !== null && tagName !== oldTag ) {
|
|
1959
1974
|
findQuery = {
|
|
1960
1975
|
clientId,
|
|
1961
|
-
tagName: { $regex: `^${
|
|
1976
|
+
tagName: { $regex: `^${escapedOldTag}$`, $options: 'i' },
|
|
1962
1977
|
};
|
|
1963
1978
|
} else {
|
|
1964
1979
|
findQuery = {
|
|
1965
1980
|
clientId,
|
|
1966
|
-
tagName: { $regex: `^${
|
|
1981
|
+
tagName: { $regex: `^${escapedTagName}$`, $options: 'i' },
|
|
1967
1982
|
};
|
|
1968
1983
|
}
|
|
1969
|
-
|
|
1984
|
+
await externalService.updateMany( { zoneName: oldTag, clientId: req.body.clientId }, { zoneName: req.body.tagName } );
|
|
1985
|
+
updateOldData( req, res );
|
|
1970
1986
|
let customZoneTagDetails = await customZoneTagService.findOne( findQuery );
|
|
1971
1987
|
|
|
1972
1988
|
if ( !customZoneTagDetails ) {
|
|
@@ -1985,7 +2001,7 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
1985
2001
|
if ( isTagNameChanging ) {
|
|
1986
2002
|
const existingTagWithNewName = await customZoneTagService.findOne( {
|
|
1987
2003
|
clientId,
|
|
1988
|
-
tagName: { $regex: `^${
|
|
2004
|
+
tagName: { $regex: `^${escapedTagName}$`, $options: 'i' },
|
|
1989
2005
|
} );
|
|
1990
2006
|
|
|
1991
2007
|
// If a tag with the new name exists and it's not the same record we're updating, return error
|
|
@@ -2022,8 +2038,10 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
2022
2038
|
if ( oldGroupNameStr !== newGroupNameStr ) {
|
|
2023
2039
|
// Remove tag from old group if oldGroupName exists
|
|
2024
2040
|
if ( actualOldGroupName ) {
|
|
2041
|
+
// Escape regex special characters in actualOldGroupName
|
|
2042
|
+
const escapedActualOldGroupName = actualOldGroupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
2025
2043
|
const oldGroupDoc = await customzonegrouping.findOne(
|
|
2026
|
-
{ clientId, groupName: { $regex: `^${
|
|
2044
|
+
{ clientId, groupName: { $regex: `^${escapedActualOldGroupName}$`, $options: 'i' } },
|
|
2027
2045
|
);
|
|
2028
2046
|
if ( oldGroupDoc ) {
|
|
2029
2047
|
await customzonegrouping.updateOne(
|
|
@@ -2036,8 +2054,10 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
2036
2054
|
|
|
2037
2055
|
// Add tag to new group if groupName exists
|
|
2038
2056
|
if ( groupName ) {
|
|
2057
|
+
// Escape regex special characters in groupName
|
|
2058
|
+
const escapedGroupName = groupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
2039
2059
|
let newGroupDoc = await customzonegrouping.findOne(
|
|
2040
|
-
{ clientId, groupName: { $regex: `^${
|
|
2060
|
+
{ clientId, groupName: { $regex: `^${escapedGroupName}$`, $options: 'i' } },
|
|
2041
2061
|
);
|
|
2042
2062
|
|
|
2043
2063
|
if ( !newGroupDoc && !isExistingGroup ) {
|
|
@@ -2060,7 +2080,9 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
2060
2080
|
} else if ( groupName && oldGroupNameStr === newGroupNameStr && oldTag && tagName !== oldTag ) {
|
|
2061
2081
|
// If groupName is same (and not null) but tagName changed, update the tagName in the group's zonesTagged
|
|
2062
2082
|
console.log( 'Group name same but tagName changed, updating group zonesTagged' );
|
|
2063
|
-
|
|
2083
|
+
// Escape regex special characters in groupName
|
|
2084
|
+
const escapedGroupName = groupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
2085
|
+
const groupDoc = await customzonegrouping.findOne( { clientId, groupName: { $regex: `^${escapedGroupName}$`, $options: 'i' } } );
|
|
2064
2086
|
if ( groupDoc ) {
|
|
2065
2087
|
await customzonegrouping.updateOne(
|
|
2066
2088
|
{ _id: groupDoc._id },
|
|
@@ -2089,13 +2111,13 @@ export const updateZoneCustomTag = async ( req, res ) => {
|
|
|
2089
2111
|
// If tagName changed, update tagging collection records with oldTag to have new tagName and groupName
|
|
2090
2112
|
await taggingService.updateMany(
|
|
2091
2113
|
{ clientId, tagName: oldTag },
|
|
2092
|
-
{ $set: { tagName, groupName: groupName || null } },
|
|
2114
|
+
{ $set: { tagName, 'groupName': groupName || null, 'coordinates.$[].zoneName': tagName } },
|
|
2093
2115
|
);
|
|
2094
2116
|
} else if ( groupName !== oldGroupName ) {
|
|
2095
2117
|
// If only groupName changed, update tagging collection with new groupName
|
|
2096
2118
|
await taggingService.updateMany(
|
|
2097
2119
|
{ clientId, tagName },
|
|
2098
|
-
{ $set: { groupName: groupName || null } },
|
|
2120
|
+
{ $set: { 'groupName': groupName || null } },
|
|
2099
2121
|
);
|
|
2100
2122
|
}
|
|
2101
2123
|
|
|
@@ -2184,7 +2206,7 @@ export const getZoneGroupDetails = async ( req, res ) => {
|
|
|
2184
2206
|
searchValue,
|
|
2185
2207
|
sortColumName,
|
|
2186
2208
|
sortBy,
|
|
2187
|
-
limit
|
|
2209
|
+
limit,
|
|
2188
2210
|
offset = 1,
|
|
2189
2211
|
export: isExport,
|
|
2190
2212
|
} = req.body;
|
|
@@ -2272,10 +2294,10 @@ export const getZoneGroupDetails = async ( req, res ) => {
|
|
|
2272
2294
|
|
|
2273
2295
|
...( isExport ?
|
|
2274
2296
|
[] :
|
|
2275
|
-
[
|
|
2297
|
+
limit ? [
|
|
2276
2298
|
{ $skip: ( offset - 1 ) * limit },
|
|
2277
2299
|
{ $limit: Number( limit ) },
|
|
2278
|
-
] ),
|
|
2300
|
+
] : [] ),
|
|
2279
2301
|
],
|
|
2280
2302
|
},
|
|
2281
2303
|
},
|
|
@@ -2293,6 +2315,7 @@ export const getZoneGroupDetails = async ( req, res ) => {
|
|
|
2293
2315
|
const totalZoneCount = await customZoneTagService.count( { clientId } );
|
|
2294
2316
|
|
|
2295
2317
|
if ( isExport && zoneGroupList.length ) {
|
|
2318
|
+
console.log( 'Exporting Zone Group Data:', JSON.stringify( zoneGroupList ) );
|
|
2296
2319
|
const exportdata = zoneGroupList.map( ( element ) => ( {
|
|
2297
2320
|
'Zone Group Name': element.groupName || '--',
|
|
2298
2321
|
'Zones tagged': Array.isArray( element.zonesTagged ) ?
|
|
@@ -2452,10 +2475,13 @@ export const addZoneGroup = async ( req, res ) => {
|
|
|
2452
2475
|
return res.sendError( 'clientId and groupName are required', 400 );
|
|
2453
2476
|
}
|
|
2454
2477
|
|
|
2478
|
+
// Escape regex special characters in groupName to avoid invalid regex patterns
|
|
2479
|
+
const escapedGroupName = groupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
2480
|
+
|
|
2455
2481
|
// Case-insensitive check for existing group
|
|
2456
2482
|
const existingGroup = await customzonegrouping.findOne( {
|
|
2457
2483
|
clientId,
|
|
2458
|
-
groupName: { $regex: `^${
|
|
2484
|
+
groupName: { $regex: `^${escapedGroupName}$`, $options: 'i' },
|
|
2459
2485
|
} );
|
|
2460
2486
|
|
|
2461
2487
|
if ( existingGroup ) {
|
|
@@ -2526,10 +2552,14 @@ export const updateZoneGroup = async ( req, res ) => {
|
|
|
2526
2552
|
}
|
|
2527
2553
|
|
|
2528
2554
|
let findGroup = await customzonegrouping.findOne( { _id: _id } );
|
|
2555
|
+
|
|
2556
|
+
// Escape regex special characters in groupName to avoid invalid regex patterns
|
|
2557
|
+
const escapedGroupName = groupName.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
2558
|
+
|
|
2529
2559
|
// Case-insensitive check for existing group (excluding current group)
|
|
2530
2560
|
const existingGroup = await customzonegrouping.findOne( {
|
|
2531
2561
|
clientId: clientId,
|
|
2532
|
-
groupName: { $regex: `^${
|
|
2562
|
+
groupName: { $regex: `^${escapedGroupName}$`, $options: 'i' },
|
|
2533
2563
|
_id: { $ne: _id },
|
|
2534
2564
|
} );
|
|
2535
2565
|
if ( existingGroup && existingGroup.groupName ) {
|
|
@@ -2698,7 +2728,7 @@ export const deleteZoneGroup = async ( req, res ) => {
|
|
|
2698
2728
|
};
|
|
2699
2729
|
|
|
2700
2730
|
export async function oldTagsMigration() {
|
|
2701
|
-
let uniqueTags = await taggingService.find( { productName: 'tangoZone' } );
|
|
2731
|
+
let uniqueTags = await taggingService.find( { productName: 'tangoZone', clientId: '440' } );
|
|
2702
2732
|
const result = _.uniqBy( uniqueTags, 'tagName' );
|
|
2703
2733
|
|
|
2704
2734
|
|