github-actions[bot]
Automated Deploy: 23110475c742a5d4f03930b55bca09042215c1dd
1fe7075
Raw History Blame Contribute Delete
883 Bytes
import type { AppConfig } from '../config/app-config.interface.js';
import { UserRole, type Subscription } from '../generated/prisma/client.js';
import type { Allowance } from './interfaces/allowance.interface.js';
/** Admins: unlimited. Subscribers: the plan's monthly allowance. Everyone else: the lifetime free tries. */
export function allowanceFor(role: UserRole, subscription: Subscription | null, config: AppConfig): Allowance {
if (role === UserRole.admin) return { plan: 'unlimited', limit: null, countFrom: null, renewsAt: null };
if (subscription) {
return {
plan: subscription.plan,
limit: config.stripe.plans[subscription.plan].monthlyGenerations,
countFrom: subscription.currentPeriodStart,
renewsAt: subscription.currentPeriodEnd,
};
}
return { plan: 'free', limit: config.freeGenerations, countFrom: null, renewsAt: null };
}