tango-app-api-store-zone 3.3.1-beta.23 → 3.3.1-beta.25
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
|
@@ -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,43 @@ 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
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1310
|
+
console.log( '🚀 ~ updateOldData ~ camDetails:', camDetails );
|
|
1311
|
+
if ( camDetails ) {
|
|
1312
|
+
const response = await axios.post( JSON.parse( process.env.URL ).zoneTaggingLamdaUrl, camDetails );
|
|
1313
|
+
|
|
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
|
+
|
|
1323
|
+
let upload = await fileUpload( fileData );
|
|
1324
|
+
if ( !upload.Key ) {
|
|
1325
|
+
logger.error( { message: `JSON Upload Error`, store: item.storeId } );
|
|
1326
|
+
}
|
|
1327
|
+
if ( index == 0 ) {
|
|
1328
|
+
res.sendSuccess( 'Zone Updated Successfully' );
|
|
1329
|
+
}
|
|
1330
|
+
} else {
|
|
1331
|
+
logger.error( { message: 'no data', store: item.storeId } );
|
|
1332
|
+
return res.sendError( 'something went wrong', 500 );
|
|
1328
1333
|
}
|
|
1329
|
-
} else {
|
|
1330
|
-
logger.error( { message: 'no data', store: item.storeId } );
|
|
1331
|
-
// return res.sendError( 'something went wrong', 500 );
|
|
1332
1334
|
}
|
|
1333
1335
|
}
|
|
1336
|
+
} else {
|
|
1337
|
+
res.sendSuccess( 'Zone Updated Successfully' );
|
|
1334
1338
|
}
|
|
1335
1339
|
} catch ( e ) {
|
|
1340
|
+
console.log( '🚀 ~ updateOldData ~ e:', e );
|
|
1336
1341
|
logger.error( { error: e, function: 'updateOldData' } );
|
|
1337
1342
|
return res.sendError( e, 500 );
|
|
1338
1343
|
}
|
|
@@ -1800,33 +1805,61 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1800
1805
|
const zoneTagDataList = [];
|
|
1801
1806
|
const zoneGroupDataMap = new Map();
|
|
1802
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
|
+
}
|
|
1803
1829
|
|
|
1804
1830
|
// Process each zone in the array
|
|
1805
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
|
+
|
|
1806
1838
|
const zoneTagData = {
|
|
1807
1839
|
clientId: clientId,
|
|
1808
1840
|
tagName: zone.tagName,
|
|
1809
1841
|
rgbColor: zone.rgbColor,
|
|
1810
1842
|
rgbBorderColor: zone.rgbBorderColor,
|
|
1811
|
-
groupName:
|
|
1843
|
+
groupName: normalizedGroupName,
|
|
1812
1844
|
productName: zone.productName,
|
|
1813
1845
|
};
|
|
1814
1846
|
zoneTagDataList.push( zoneTagData );
|
|
1815
1847
|
createdTagNames.push( zone.tagName );
|
|
1816
1848
|
|
|
1817
1849
|
// Prepare zone group data if groupName is provided
|
|
1818
|
-
if (
|
|
1819
|
-
|
|
1820
|
-
|
|
1850
|
+
if ( normalizedGroupName ) {
|
|
1851
|
+
// Use normalized groupName (existing case or user case)
|
|
1852
|
+
if ( !zoneGroupDataMap.has( normalizedGroupName ) ) {
|
|
1853
|
+
zoneGroupDataMap.set( normalizedGroupName, {
|
|
1821
1854
|
clientId: clientId,
|
|
1822
|
-
groupName:
|
|
1855
|
+
groupName: normalizedGroupName,
|
|
1823
1856
|
productName: zone.productName,
|
|
1824
1857
|
zonesTagged: new Set(),
|
|
1825
1858
|
} );
|
|
1826
1859
|
}
|
|
1827
1860
|
|
|
1828
1861
|
// Collect all tagNames for this group so that we can append them
|
|
1829
|
-
const groupEntry = zoneGroupDataMap.get(
|
|
1862
|
+
const groupEntry = zoneGroupDataMap.get( normalizedGroupName );
|
|
1830
1863
|
groupEntry.zonesTagged.add( zone.tagName );
|
|
1831
1864
|
}
|
|
1832
1865
|
}
|
|
@@ -1878,11 +1911,13 @@ export const uploadBulkZoneTag = async ( req, res ) => {
|
|
|
1878
1911
|
}
|
|
1879
1912
|
|
|
1880
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)
|
|
1881
1915
|
for ( const zone of zonesArray ) {
|
|
1882
1916
|
if ( zone.groupName && zone.groupName !== '' && zone.groupName !== null ) {
|
|
1917
|
+
const normalizedGroupName = groupNameMapping.get( zone.groupName.toLowerCase() ) || zone.groupName;
|
|
1883
1918
|
await taggingService.updateMany(
|
|
1884
1919
|
{ clientId, tagName: zone.tagName },
|
|
1885
|
-
{ $set: { groupName:
|
|
1920
|
+
{ $set: { groupName: normalizedGroupName } },
|
|
1886
1921
|
);
|
|
1887
1922
|
}
|
|
1888
1923
|
}
|
|
@@ -2113,8 +2148,14 @@ export const deleteZoneCustomTag = async ( req, res ) => {
|
|
|
2113
2148
|
if ( !zoneTagDetails || zoneTagDetails?.length == 0 ) {
|
|
2114
2149
|
return res.sendError( 'No data found', 400 );
|
|
2115
2150
|
}
|
|
2116
|
-
|
|
2151
|
+
updateOldData( req, res );
|
|
2117
2152
|
await customZoneTagService.deleteOne( { clientId, tagName } );
|
|
2153
|
+
await taggingService.deleteMany(
|
|
2154
|
+
{
|
|
2155
|
+
clientId,
|
|
2156
|
+
tagName: { $in: tagName },
|
|
2157
|
+
},
|
|
2158
|
+
);
|
|
2118
2159
|
const logObj = {
|
|
2119
2160
|
clientId: req.body?.clientId,
|
|
2120
2161
|
userName: req.user?.userName,
|
|
@@ -2127,7 +2168,7 @@ export const deleteZoneCustomTag = async ( req, res ) => {
|
|
|
2127
2168
|
showTo: [ 'client', 'tango' ],
|
|
2128
2169
|
};
|
|
2129
2170
|
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH )?.activityLog, logObj );
|
|
2130
|
-
return res.sendSuccess( 'ZoneName Deleted Successfully' );
|
|
2171
|
+
// return res.sendSuccess( 'ZoneName Deleted Successfully' );
|
|
2131
2172
|
} catch ( e ) {
|
|
2132
2173
|
logger.error( { error: e, function: 'deleteZoneCustomTag' } );
|
|
2133
2174
|
return res.sendError( e, 500 );
|
|
@@ -2257,7 +2298,7 @@ export const getZoneGroupDetails = async ( req, res ) => {
|
|
|
2257
2298
|
'Zones tagged': Array.isArray( element.zonesTagged ) ?
|
|
2258
2299
|
element.zonesTagged.map( ( zone ) => zone.tagName ).filter( Boolean ).
|
|
2259
2300
|
join( ', ' ) : '--',
|
|
2260
|
-
'Zones tagged Count': element.
|
|
2301
|
+
'Zones tagged Count': element.zonesTagged.length || 0,
|
|
2261
2302
|
} ) );
|
|
2262
2303
|
await download( exportdata, res );
|
|
2263
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,33 +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
48
|
// Attach clientId to req for use in controller
|
|
77
49
|
req.bulkZoneClientId = clientId;
|
|
78
50
|
next();
|