feat: add subscription plans. Add admin panel. Add password recovery
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user