tango-app-api-infra 3.9.5-vms.62 → 3.9.5-vms.64
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
|
@@ -564,11 +564,13 @@ export async function ticketCreation( req, res, next ) {
|
|
|
564
564
|
$match: {
|
|
565
565
|
clientId: getstoreName.clientId,
|
|
566
566
|
role: 'admin',
|
|
567
|
+
isActive: true,
|
|
567
568
|
},
|
|
568
569
|
},
|
|
569
570
|
];
|
|
570
571
|
|
|
571
572
|
const finduserList = await aggregateUser( userQuery );
|
|
573
|
+
console.log( '🚀 ~ ticketCreation ~ finduserList:', finduserList.length );
|
|
572
574
|
|
|
573
575
|
const createdOn = dayjs().format( 'DD MMM YYYY' );
|
|
574
576
|
const title = `${getstoreName?.storeName} Have raised a ticket for a Footfall Mismatch`;
|
|
@@ -594,10 +596,12 @@ export async function ticketCreation( req, res, next ) {
|
|
|
594
596
|
m.name === 'reviewer' && ( m.isAdd === true || m.isEdit === true ),
|
|
595
597
|
),
|
|
596
598
|
);
|
|
599
|
+
console.log( '🚀 ~ ticketCreation ~ ticketsFeature:', ticketsFeature );
|
|
597
600
|
|
|
598
601
|
if ( !ticketsFeature ) return;
|
|
599
602
|
|
|
600
603
|
const notifyUser = await getAssinedStore( userData, req.body.storeId );
|
|
604
|
+
console.log( '🚀 ~ ticketCreation ~ notifyUser:', notifyUser );
|
|
601
605
|
if ( !notifyUser || !userData?.fcmToken ) return;
|
|
602
606
|
|
|
603
607
|
await sendPushNotification( title, description, userData.fcmToken, Data );
|
|
@@ -1260,11 +1264,12 @@ export async function ticketReview( req, res, next ) {
|
|
|
1260
1264
|
$match: {
|
|
1261
1265
|
clientId: getstoreName.clientId,
|
|
1262
1266
|
role: 'admin',
|
|
1267
|
+
isActive: true,
|
|
1263
1268
|
},
|
|
1264
1269
|
},
|
|
1265
1270
|
];
|
|
1266
1271
|
let finduserList = await aggregateUser( userQuery );
|
|
1267
|
-
console.log( '🚀 ~ ticketReview ~ finduserList:', finduserList );
|
|
1272
|
+
console.log( '🚀 ~ ticketReview ~ finduserList:', finduserList.length );
|
|
1268
1273
|
|
|
1269
1274
|
// return;
|
|
1270
1275
|
for ( let userData of finduserList ) {
|
|
@@ -1759,6 +1764,7 @@ export async function ticketApprove( req, res, next ) {
|
|
|
1759
1764
|
$match: {
|
|
1760
1765
|
clientId: getstoreName.clientId,
|
|
1761
1766
|
role: 'admin',
|
|
1767
|
+
isActive: true,
|
|
1762
1768
|
},
|
|
1763
1769
|
},
|
|
1764
1770
|
];
|
|
@@ -1808,71 +1814,85 @@ export async function ticketApprove( req, res, next ) {
|
|
|
1808
1814
|
}
|
|
1809
1815
|
}
|
|
1810
1816
|
|
|
1811
|
-
|
|
1812
1817
|
export async function getAssinedStore( user, storeId ) {
|
|
1813
|
-
if ( user
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
// Fetch clusters and teams in parallel
|
|
1817
|
-
const [ clustersList, teamsList ] = await Promise.all( [
|
|
1818
|
-
findcluster( { clientId: user.clientId, Teamlead: { $elemMatch: { email: user.email } } } ),
|
|
1819
|
-
findteams( { clientId: user.clientId, Teamlead: { $elemMatch: { email: user.email } } } ),
|
|
1820
|
-
] );
|
|
1821
|
-
|
|
1822
|
-
// Process clusters
|
|
1823
|
-
if ( clustersList.length > 0 ) {
|
|
1824
|
-
for ( let cluster of clustersList ) {
|
|
1825
|
-
cluster.stores.forEach( ( store ) => storeIds.add( store.storeId ) );
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1818
|
+
if ( !user || user.userType !== 'client' || user.role === 'superadmin' ) {
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1828
1821
|
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
let findUser = await findOneUser( { _id: user.userId } );
|
|
1834
|
-
if ( findUser && findUser.assignedStores?.length > 0 ) {
|
|
1835
|
-
findUser.assignedStores.forEach( ( store ) => storeIds.add( store.storeId ) );
|
|
1836
|
-
}
|
|
1822
|
+
const clientId = user.clientId;
|
|
1823
|
+
const storeIds = new Set(
|
|
1824
|
+
user.assignedStores?.map( ( store ) => store.storeId ) ?? [],
|
|
1825
|
+
);
|
|
1837
1826
|
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
cluster.stores.forEach( ( store ) => storeIds.add( store.storeId ) );
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1827
|
+
const addClusterStores = ( clusters ) => {
|
|
1828
|
+
if ( !clusters?.length ) return;
|
|
1829
|
+
for ( const cluster of clusters ) {
|
|
1830
|
+
cluster.stores?.forEach( ( store ) => storeIds.add( store.storeId ) );
|
|
1847
1831
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
// Fetch all top-level data in parallel
|
|
1835
|
+
const [ clustersList, teamsList, teamMemberList ] = await Promise.all( [
|
|
1836
|
+
findcluster( {
|
|
1837
|
+
clientId,
|
|
1838
|
+
Teamlead: { $elemMatch: { email: user.email } },
|
|
1839
|
+
} ),
|
|
1840
|
+
findteams( {
|
|
1841
|
+
clientId,
|
|
1842
|
+
Teamlead: { $elemMatch: { email: user.email } },
|
|
1843
|
+
} ),
|
|
1844
|
+
findteams( {
|
|
1845
|
+
clientId,
|
|
1846
|
+
users: { $elemMatch: { email: user.email } },
|
|
1847
|
+
} ),
|
|
1848
|
+
] );
|
|
1849
|
+
|
|
1850
|
+
// 1) Clusters where this user is Teamlead
|
|
1851
|
+
addClusterStores( clustersList );
|
|
1852
|
+
|
|
1853
|
+
// 2) Teams where this user is Teamlead → their users + their clusters
|
|
1854
|
+
if ( teamsList?.length ) {
|
|
1855
|
+
for ( const team of teamsList ) {
|
|
1856
|
+
if ( !team.users?.length ) continue;
|
|
1857
|
+
|
|
1858
|
+
await Promise.all(
|
|
1859
|
+
team.users.map( async ( teamUser ) => {
|
|
1860
|
+
const foundUser = await findOneUser( { _id: teamUser.userId } );
|
|
1861
|
+
if ( !foundUser ) return;
|
|
1862
|
+
|
|
1863
|
+
// Direct assigned stores of that user
|
|
1864
|
+
if ( foundUser.assignedStores?.length ) {
|
|
1865
|
+
foundUser.assignedStores.forEach( ( store ) =>
|
|
1866
|
+
storeIds.add( store.storeId ),
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
// Clusters where this user is Teamlead
|
|
1871
|
+
const userClustersList = await findcluster( {
|
|
1872
|
+
clientId,
|
|
1873
|
+
Teamlead: { $elemMatch: { email: foundUser.email } },
|
|
1874
|
+
} );
|
|
1875
|
+
addClusterStores( userClustersList );
|
|
1876
|
+
} ),
|
|
1877
|
+
);
|
|
1869
1878
|
}
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// 3) Teams where this user is a member → clusters by teamName
|
|
1882
|
+
if ( teamMemberList?.length ) {
|
|
1883
|
+
for ( const team of teamMemberList ) {
|
|
1884
|
+
const clusterList = await findcluster( {
|
|
1885
|
+
clientId,
|
|
1886
|
+
teams: { $elemMatch: { name: team.teamName } },
|
|
1887
|
+
} );
|
|
1888
|
+
addClusterStores( clusterList );
|
|
1876
1889
|
}
|
|
1877
1890
|
}
|
|
1891
|
+
|
|
1892
|
+
const assignedStores = Array.from( storeIds );
|
|
1893
|
+
|
|
1894
|
+
// Previously you returned `true` in both branches.
|
|
1895
|
+
// Assuming you actually want to check membership:
|
|
1896
|
+
return assignedStores.includes( storeId );
|
|
1878
1897
|
}
|
|
1898
|
+
|