first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
18
packages/auth/lib/helper.ts
Normal file
18
packages/auth/lib/helper.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import type { ActiveOrganization } from "../auth";
|
||||
|
||||
export function isOrganizationAdmin(
|
||||
organization?: ActiveOrganization | null,
|
||||
user?: {
|
||||
id: string;
|
||||
role?: string | null;
|
||||
} | null,
|
||||
) {
|
||||
const userOrganizationRole = organization?.members.find(
|
||||
(member) => member.userId === user?.id,
|
||||
)?.role;
|
||||
|
||||
return (
|
||||
["owner", "admin"].includes(userOrganizationRole ?? "") ||
|
||||
user?.role === "admin"
|
||||
);
|
||||
}
|
||||
34
packages/auth/lib/organization.ts
Normal file
34
packages/auth/lib/organization.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { getOrganizationWithPurchasesAndMembersCount } from "@repo/database";
|
||||
import { logger } from "@repo/logs";
|
||||
import { setSubscriptionSeats } from "@repo/payments";
|
||||
|
||||
export async function updateSeatsInOrganizationSubscription(
|
||||
organizationId: string,
|
||||
) {
|
||||
const organization =
|
||||
await getOrganizationWithPurchasesAndMembersCount(organizationId);
|
||||
|
||||
if (!organization?.purchases.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeSubscription = organization.purchases.find(
|
||||
(purchase) => purchase.type === "SUBSCRIPTION",
|
||||
);
|
||||
|
||||
if (!activeSubscription?.subscriptionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await setSubscriptionSeats({
|
||||
id: activeSubscription.subscriptionId,
|
||||
seats: organization.membersCount,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error("Could not update seats in organization subscription", {
|
||||
organizationId,
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue