feat: add subscription plans. Add admin panel. Add password recovery

This commit is contained in:
Jose Selesan
2026-10-24 18:31:55 -03:00
parent f5e77c99f6
commit cd82a1e549
42 changed files with 2017 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import type { PrismaClient, SubscriptionStatus } from '@generated/prisma/client';
import type { Prisma, PrismaClient, SubscriptionStatus } from '@generated/prisma/client';
import type { Plan, PlanFeature, PlanLimits, ProblemDetails, Result } from '@gruperly/shared';
import { err, ok, PLAN_LIMITS } from '@gruperly/shared';
import {
@@ -53,6 +53,21 @@ export function resolvePlan(
return { plan: 'FREE', graceUntil: null };
}
/**
* `resolvePlan` written as a query, for listing accounts by plan: a
* subscription is Pro when its paid period (or, before the first charge, its
* authorization) is younger than the grace period. Keep both in step.
*/
export function proSubscriptionWhere(now: Date, graceDays: number): Prisma.BillingSubscriptionWhereInput {
const cutoff = new Date(now.getTime() - graceDays * DAY_MS);
return {
OR: [
{ paidThrough: { gt: cutoff } },
{ paidThrough: null, status: 'AUTHORIZED', authorizedAt: { gt: cutoff } },
],
};
}
export type PlanUsage = { groups: number; attendees: number };
export function exceedsLimits(limits: PlanLimits, usage: PlanUsage): boolean {