mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-22 16:55:44 +00:00
Allow deleting account with trial
This commit is contained in:
@@ -19,12 +19,13 @@ import { eq, and, ne } from "drizzle-orm";
|
|||||||
|
|
||||||
export async function getOrgTierData(
|
export async function getOrgTierData(
|
||||||
orgId: string
|
orgId: string
|
||||||
): Promise<{ tier: Tier | null; active: boolean }> {
|
): Promise<{ tier: Tier | null; active: boolean; isTrial: boolean }> {
|
||||||
let tier: Tier | null = null;
|
let tier: Tier | null = null;
|
||||||
let active = false;
|
let active = false;
|
||||||
|
let isTrial = false;
|
||||||
|
|
||||||
if (build !== "saas") {
|
if (build !== "saas") {
|
||||||
return { tier, active };
|
return { tier, active, isTrial };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -35,7 +36,7 @@ export async function getOrgTierData(
|
|||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!org) {
|
if (!org) {
|
||||||
return { tier, active };
|
return { tier, active, isTrial };
|
||||||
}
|
}
|
||||||
|
|
||||||
let orgIdToUse = org.orgId;
|
let orgIdToUse = org.orgId;
|
||||||
@@ -44,7 +45,7 @@ export async function getOrgTierData(
|
|||||||
logger.warn(
|
logger.warn(
|
||||||
`Org ${orgId} is not a billing org and does not have a billingOrgId`
|
`Org ${orgId} is not a billing org and does not have a billingOrgId`
|
||||||
);
|
);
|
||||||
return { tier, active };
|
return { tier, active, isTrial };
|
||||||
}
|
}
|
||||||
orgIdToUse = org.billingOrgId;
|
orgIdToUse = org.billingOrgId;
|
||||||
}
|
}
|
||||||
@@ -57,7 +58,7 @@ export async function getOrgTierData(
|
|||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!customer) {
|
if (!customer) {
|
||||||
return { tier, active };
|
return { tier, active, isTrial };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query for active subscriptions that are not license type
|
// Query for active subscriptions that are not license type
|
||||||
@@ -84,11 +85,13 @@ export async function getOrgTierData(
|
|||||||
tier = subscription.type;
|
tier = subscription.type;
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isTrial = subscription.trial ?? false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If org not found or error occurs, return null tier and inactive
|
// If org not found or error occurs, return null tier and inactive
|
||||||
// This is acceptable behavior as per the function signature
|
// This is acceptable behavior as per the function signature
|
||||||
}
|
}
|
||||||
|
|
||||||
return { tier, active };
|
return { tier, active, isTrial };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,9 @@ export async function deleteMyAccount(
|
|||||||
(r) => r.isBillingOrg && r.isOwner
|
(r) => r.isBillingOrg && r.isOwner
|
||||||
)?.orgId;
|
)?.orgId;
|
||||||
if (primaryOrgId) {
|
if (primaryOrgId) {
|
||||||
const { tier, active } = await getOrgTierData(primaryOrgId);
|
const { tier, active, isTrial } =
|
||||||
if (active && tier) {
|
await getOrgTierData(primaryOrgId);
|
||||||
|
if (active && tier && !isTrial) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.BAD_REQUEST,
|
HttpCode.BAD_REQUEST,
|
||||||
|
|||||||
Reference in New Issue
Block a user