@goweekdays/core 2.11.16 → 2.11.17
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +60 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1947,6 +1947,49 @@ function useMemberRepo() {
|
|
|
1947
1947
|
);
|
|
1948
1948
|
}
|
|
1949
1949
|
}
|
|
1950
|
+
async function getByUserOrg(user, org) {
|
|
1951
|
+
try {
|
|
1952
|
+
org = new ObjectId7(org);
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
throw new BadRequestError7("Invalid organization ID.");
|
|
1955
|
+
}
|
|
1956
|
+
try {
|
|
1957
|
+
user = new ObjectId7(user);
|
|
1958
|
+
} catch (error) {
|
|
1959
|
+
throw new BadRequestError7("Invalid user ID.");
|
|
1960
|
+
}
|
|
1961
|
+
try {
|
|
1962
|
+
const cacheKey = makeCacheKey4(namespace_collection, {
|
|
1963
|
+
user: String(user),
|
|
1964
|
+
org: String(org)
|
|
1965
|
+
});
|
|
1966
|
+
const cached = await getCache(cacheKey);
|
|
1967
|
+
if (cached) {
|
|
1968
|
+
logger4.log({
|
|
1969
|
+
level: "info",
|
|
1970
|
+
message: `Cache hit for getByUserOrg member: ${cacheKey}`
|
|
1971
|
+
});
|
|
1972
|
+
return cached;
|
|
1973
|
+
}
|
|
1974
|
+
const data = await collection.findOne({ user, org });
|
|
1975
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
1976
|
+
logger4.log({
|
|
1977
|
+
level: "info",
|
|
1978
|
+
message: `Cache set for member by user and org: ${cacheKey}`
|
|
1979
|
+
});
|
|
1980
|
+
}).catch((err) => {
|
|
1981
|
+
logger4.log({
|
|
1982
|
+
level: "error",
|
|
1983
|
+
message: `Failed to set cache for member by user and org: ${err.message}`
|
|
1984
|
+
});
|
|
1985
|
+
});
|
|
1986
|
+
return data;
|
|
1987
|
+
} catch (error) {
|
|
1988
|
+
throw new InternalServerError5(
|
|
1989
|
+
"Internal server error, failed to retrieve member."
|
|
1990
|
+
);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1950
1993
|
return {
|
|
1951
1994
|
createIndexes,
|
|
1952
1995
|
add,
|
|
@@ -1966,7 +2009,8 @@ function useMemberRepo() {
|
|
|
1966
2009
|
updateStatusById,
|
|
1967
2010
|
deleteById,
|
|
1968
2011
|
updateStatusByOrg,
|
|
1969
|
-
countUserByOrg
|
|
2012
|
+
countUserByOrg,
|
|
2013
|
+
getByUserOrg
|
|
1970
2014
|
};
|
|
1971
2015
|
}
|
|
1972
2016
|
|
|
@@ -10806,7 +10850,11 @@ function useVerificationService() {
|
|
|
10806
10850
|
getVerifications: _getVerifications
|
|
10807
10851
|
} = useVerificationRepo();
|
|
10808
10852
|
const { getUserByEmail } = useUserRepo();
|
|
10809
|
-
const {
|
|
10853
|
+
const {
|
|
10854
|
+
add: addMember,
|
|
10855
|
+
countUserByOrg,
|
|
10856
|
+
getByUserOrg: getMemberByUserOrg
|
|
10857
|
+
} = useMemberRepo();
|
|
10810
10858
|
const { getById: getOrgById } = useOrgRepo();
|
|
10811
10859
|
const { getById: getRoleById } = useRoleRepo();
|
|
10812
10860
|
async function createUserInvite({
|
|
@@ -11138,8 +11186,17 @@ function useVerificationService() {
|
|
|
11138
11186
|
);
|
|
11139
11187
|
}
|
|
11140
11188
|
}
|
|
11189
|
+
const user = await getUserByEmail(value.email);
|
|
11190
|
+
let userId = "";
|
|
11191
|
+
if (user) {
|
|
11192
|
+
userId = String(user._id);
|
|
11193
|
+
}
|
|
11141
11194
|
const memberCount = await countUserByOrg(String(value.org));
|
|
11142
|
-
|
|
11195
|
+
const existingMember = await getMemberByUserOrg(
|
|
11196
|
+
userId,
|
|
11197
|
+
String(value.org)
|
|
11198
|
+
);
|
|
11199
|
+
if (subscription.seats <= memberCount && !existingMember) {
|
|
11143
11200
|
throw new BadRequestError49(
|
|
11144
11201
|
"Organization has reached the maximum number of members for its subscription plan."
|
|
11145
11202
|
);
|