Added backend limits
This commit is contained in:
@@ -94,6 +94,7 @@ import {
|
||||
getMembershipForUser,
|
||||
getNextWorkspaceId,
|
||||
getWorkspaceById,
|
||||
getWorkspaceBirdCount,
|
||||
getWorkspaceTotalBirdCount,
|
||||
listOwnedWorkspacesByOwnerEmail,
|
||||
listRescueWorkspacesForAdmin,
|
||||
@@ -951,6 +952,26 @@ const subscriptionAllowsWrite = (workspace: WorkspaceRow) => {
|
||||
return workspace.subscription_status === 'active' || workspace.subscription_status === 'trialing';
|
||||
};
|
||||
|
||||
const getBillingPlanBirdLimit = (billingPlan: BillingPlan) => {
|
||||
if (billingPlan === 'rescue_free') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (billingPlan === 'household_basic') {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (billingPlan === 'household_plus') {
|
||||
return 10;
|
||||
}
|
||||
|
||||
if (billingPlan === 'household_macaw') {
|
||||
return 16;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const mapStripeSubscriptionStatus = (status: Stripe.Subscription.Status): SubscriptionStatus => {
|
||||
if (status === 'active' || status === 'trialing' || status === 'past_due' || status === 'canceled' || status === 'unpaid') {
|
||||
return status;
|
||||
@@ -3118,6 +3139,23 @@ app.post('/api/birds', requireAuth, requireWriteAccess, requireWorkspaceRole(['o
|
||||
let uploadedObjectKeyToCleanup: string | null = null;
|
||||
|
||||
try {
|
||||
const birdLimit = getBillingPlanBirdLimit(req.auth!.workspace.billing_plan);
|
||||
|
||||
if (birdLimit !== null) {
|
||||
const currentBirdCount = await getWorkspaceBirdCount(req.auth!.workspace.id);
|
||||
|
||||
if (currentBirdCount >= birdLimit) {
|
||||
res.status(409).json({
|
||||
error: 'This flock has reached the bird limit for the selected plan. Upgrade the flock subscription or memorialize a bird before adding another.',
|
||||
code: 'billing_plan_bird_limit_reached',
|
||||
birdLimit,
|
||||
currentBirdCount,
|
||||
billingPlan: req.auth!.workspace.billing_plan,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const birdId = crypto.randomUUID();
|
||||
const photoStorage = await resolveBirdPhotoStorage({
|
||||
birdId,
|
||||
|
||||
Reference in New Issue
Block a user