mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-14 13:25:21 +00:00
change back fetch subscription to not require org membership
This commit is contained in:
parent
cf97955b23
commit
ea4c29daec
1 changed files with 21 additions and 23 deletions
|
|
@ -332,9 +332,8 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su
|
||||||
// Incrememnt the seat count
|
// Incrememnt the seat count
|
||||||
if (org.stripeCustomerId) {
|
if (org.stripeCustomerId) {
|
||||||
const subscription = await fetchSubscription(org.domain);
|
const subscription = await fetchSubscription(org.domain);
|
||||||
console.log("subscription", subscription)
|
|
||||||
if (isServiceError(subscription)) {
|
if (isServiceError(subscription)) {
|
||||||
return orgInvalidSubscription();
|
throw orgInvalidSubscription();
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingSeatCount = subscription.items.data[0].quantity;
|
const existingSeatCount = subscription.items.data[0].quantity;
|
||||||
|
|
@ -548,27 +547,26 @@ export const getCustomerPortalSessionLink = async (domain: string): Promise<stri
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const fetchSubscription = (domain: string): Promise<any | ServiceError> =>
|
export const fetchSubscription = (domain: string): Promise<any | ServiceError> =>
|
||||||
withAuth((session) =>
|
withAuth(async () => {
|
||||||
withOrgMembership(session, domain, async (orgId) => {
|
const org = await prisma.org.findUnique({
|
||||||
const org = await prisma.org.findUnique({
|
where: {
|
||||||
where: {
|
domain,
|
||||||
id: orgId,
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (!org || !org.stripeCustomerId) {
|
if (!org || !org.stripeCustomerId) {
|
||||||
return notFound();
|
return notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const subscriptions = await stripe.subscriptions.list({
|
const subscriptions = await stripe.subscriptions.list({
|
||||||
customer: org.stripeCustomerId
|
customer: org.stripeCustomerId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (subscriptions.data.length === 0) {
|
if (subscriptions.data.length === 0) {
|
||||||
return notFound();
|
return notFound();
|
||||||
}
|
}
|
||||||
return subscriptions.data[0];
|
return subscriptions.data[0];
|
||||||
}));
|
});
|
||||||
|
|
||||||
export const checkIfUserHasOrg = async (userId: string): Promise<boolean | ServiceError> => {
|
export const checkIfUserHasOrg = async (userId: string): Promise<boolean | ServiceError> => {
|
||||||
const orgs = await prisma.userToOrg.findMany({
|
const orgs = await prisma.userToOrg.findMany({
|
||||||
|
|
@ -592,7 +590,7 @@ export const checkIfOrgDomainExists = async (domain: string): Promise<boolean |
|
||||||
});
|
});
|
||||||
|
|
||||||
export const removeMember = async (memberId: string, domain: string): Promise<{ success: boolean } | ServiceError> =>
|
export const removeMember = async (memberId: string, domain: string): Promise<{ success: boolean } | ServiceError> =>
|
||||||
withAuth(async (session) =>
|
withAuth(async (session) =>
|
||||||
withOrgMembership(session, domain, async (orgId) => {
|
withOrgMembership(session, domain, async (orgId) => {
|
||||||
const targetMember = await prisma.userToOrg.findUnique({
|
const targetMember = await prisma.userToOrg.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -616,7 +614,7 @@ export const removeMember = async (memberId: string, domain: string): Promise<{
|
||||||
if (!org) {
|
if (!org) {
|
||||||
return notFound();
|
return notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (org.stripeCustomerId) {
|
if (org.stripeCustomerId) {
|
||||||
const subscription = await fetchSubscription(domain);
|
const subscription = await fetchSubscription(domain);
|
||||||
if (isServiceError(subscription)) {
|
if (isServiceError(subscription)) {
|
||||||
|
|
@ -650,7 +648,7 @@ export const removeMember = async (memberId: string, domain: string): Promise<{
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getSubscriptionData = async (domain: string) =>
|
export const getSubscriptionData = async (domain: string) =>
|
||||||
withAuth(async (session) =>
|
withAuth(async (session) =>
|
||||||
withOrgMembership(session, domain, async (orgId) => {
|
withOrgMembership(session, domain, async (orgId) => {
|
||||||
const subscription = await fetchSubscription(domain);
|
const subscription = await fetchSubscription(domain);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue