@goweekdays/core 2.11.5 → 2.11.6
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 +71 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1153,6 +1153,7 @@ function useMemberRepo() {
|
|
|
1153
1153
|
try {
|
|
1154
1154
|
await collection.createIndexes([
|
|
1155
1155
|
{ key: { name: 1 } },
|
|
1156
|
+
{ key: { user: 1 } },
|
|
1156
1157
|
{ key: { status: 1 } },
|
|
1157
1158
|
{ key: { org: 1 } },
|
|
1158
1159
|
{ key: { name: "text", orgName: "text" }, name: "text_index" },
|
|
@@ -1892,6 +1893,55 @@ function useMemberRepo() {
|
|
|
1892
1893
|
);
|
|
1893
1894
|
}
|
|
1894
1895
|
}
|
|
1896
|
+
async function countUserByOrg(org) {
|
|
1897
|
+
try {
|
|
1898
|
+
org = new ObjectId7(org);
|
|
1899
|
+
} catch (error) {
|
|
1900
|
+
throw new BadRequestError7("Invalid organization ID.");
|
|
1901
|
+
}
|
|
1902
|
+
try {
|
|
1903
|
+
const cacheKey = makeCacheKey4(namespace_collection, {
|
|
1904
|
+
org: String(org),
|
|
1905
|
+
tag: "countUserByOrg"
|
|
1906
|
+
});
|
|
1907
|
+
const cached = await getCache(cacheKey);
|
|
1908
|
+
if (cached) {
|
|
1909
|
+
logger4.log({
|
|
1910
|
+
level: "info",
|
|
1911
|
+
message: `Cache hit for countUserByOrg members: ${cacheKey}`
|
|
1912
|
+
});
|
|
1913
|
+
return cached;
|
|
1914
|
+
}
|
|
1915
|
+
const data = await collection.aggregate([
|
|
1916
|
+
{ $match: { org, status: "active" } },
|
|
1917
|
+
{
|
|
1918
|
+
$group: {
|
|
1919
|
+
_id: "$user"
|
|
1920
|
+
}
|
|
1921
|
+
},
|
|
1922
|
+
{
|
|
1923
|
+
$count: "memberCount"
|
|
1924
|
+
}
|
|
1925
|
+
]).toArray();
|
|
1926
|
+
const count = data[0]?.memberCount ?? 0;
|
|
1927
|
+
setCache(cacheKey, count, 300).then(() => {
|
|
1928
|
+
logger4.log({
|
|
1929
|
+
level: "info",
|
|
1930
|
+
message: `Cache set for countUserByOrg members: ${cacheKey}`
|
|
1931
|
+
});
|
|
1932
|
+
}).catch((err) => {
|
|
1933
|
+
logger4.log({
|
|
1934
|
+
level: "error",
|
|
1935
|
+
message: `Failed to set cache for countUserByOrg members: ${err.message}`
|
|
1936
|
+
});
|
|
1937
|
+
});
|
|
1938
|
+
return count;
|
|
1939
|
+
} catch (error) {
|
|
1940
|
+
throw new InternalServerError5(
|
|
1941
|
+
"Internal server error, failed to count users."
|
|
1942
|
+
);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1895
1945
|
return {
|
|
1896
1946
|
createIndexes,
|
|
1897
1947
|
add,
|
|
@@ -1910,7 +1960,8 @@ function useMemberRepo() {
|
|
|
1910
1960
|
updateRoleById,
|
|
1911
1961
|
updateStatusById,
|
|
1912
1962
|
deleteById,
|
|
1913
|
-
updateStatusByOrg
|
|
1963
|
+
updateStatusByOrg,
|
|
1964
|
+
countUserByOrg
|
|
1914
1965
|
};
|
|
1915
1966
|
}
|
|
1916
1967
|
|
|
@@ -10559,7 +10610,7 @@ function useVerificationService() {
|
|
|
10559
10610
|
getVerifications: _getVerifications
|
|
10560
10611
|
} = useVerificationRepo();
|
|
10561
10612
|
const { getUserByEmail } = useUserRepo();
|
|
10562
|
-
const { add: addMember } = useMemberRepo();
|
|
10613
|
+
const { add: addMember, countUserByOrg } = useMemberRepo();
|
|
10563
10614
|
const { getById: getOrgById } = useOrgRepo();
|
|
10564
10615
|
const { getById: getRoleById } = useRoleRepo();
|
|
10565
10616
|
async function createUserInvite({
|
|
@@ -10858,6 +10909,7 @@ function useVerificationService() {
|
|
|
10858
10909
|
}
|
|
10859
10910
|
}
|
|
10860
10911
|
const { getByOrg } = useSubscriptionRepo();
|
|
10912
|
+
const { getByCode: getPromoByCode } = usePromoRepo();
|
|
10861
10913
|
async function inviteMember(value) {
|
|
10862
10914
|
const { error } = schemaInviteMember.validate(value);
|
|
10863
10915
|
if (error) {
|
|
@@ -10879,6 +10931,23 @@ function useVerificationService() {
|
|
|
10879
10931
|
"Organization does not have an active subscription."
|
|
10880
10932
|
);
|
|
10881
10933
|
}
|
|
10934
|
+
if (subscription.promoCode) {
|
|
10935
|
+
const promo = await getPromoByCode(subscription.promoCode);
|
|
10936
|
+
if (!promo) {
|
|
10937
|
+
throw new BadRequestError49("Promo code not found.");
|
|
10938
|
+
}
|
|
10939
|
+
if (promo.apps && promo.apps.length && !promo.apps.includes(value.app)) {
|
|
10940
|
+
throw new BadRequestError49(
|
|
10941
|
+
"Promo code is not valid for the specified app."
|
|
10942
|
+
);
|
|
10943
|
+
}
|
|
10944
|
+
}
|
|
10945
|
+
const memberCount = await countUserByOrg(String(value.org));
|
|
10946
|
+
if (subscription.seats <= memberCount) {
|
|
10947
|
+
throw new BadRequestError49(
|
|
10948
|
+
"Organization has reached the maximum number of members for its subscription plan."
|
|
10949
|
+
);
|
|
10950
|
+
}
|
|
10882
10951
|
}
|
|
10883
10952
|
let verificationData = {
|
|
10884
10953
|
type: "user-invite",
|