feat: add subscription plans. Add admin panel. Add password recovery
This commit is contained in:
88
packages/shared/src/schemas/admin.ts
Normal file
88
packages/shared/src/schemas/admin.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { z } from 'zod';
|
||||
import { BillingChargeDtoSchema, planSchema, subscriptionStatusSchema } from './billing.js';
|
||||
import { countryCodeSchema } from './country.js';
|
||||
import { createPageSchema, createPageSizeSchema, createPaginationSchema } from './pagination.js';
|
||||
|
||||
const isoDateTimeSchema = z.string().datetime();
|
||||
|
||||
// Backoffice: Gruperly's own staff looking at the professors' accounts. Read only.
|
||||
|
||||
export const AdminMeDtoSchema = z.object({
|
||||
isAdmin: z.boolean(),
|
||||
});
|
||||
export type AdminMeDto = z.output<typeof AdminMeDtoSchema>;
|
||||
|
||||
/** `NOT_SELECTED`: the professor never got past the onboarding step "Plan". */
|
||||
export const adminPlanFilterSchema = z.enum(['FREE', 'PRO', 'NOT_SELECTED']);
|
||||
export type AdminPlanFilter = z.output<typeof adminPlanFilterSchema>;
|
||||
|
||||
/** `NONE`: the professor never started a Pro subscription. */
|
||||
export const adminSubscriptionFilterSchema = z.enum([...subscriptionStatusSchema.options, 'NONE']);
|
||||
export type AdminSubscriptionFilter = z.output<typeof adminSubscriptionFilterSchema>;
|
||||
|
||||
export const AdminAccountQuerySchema = z.object({
|
||||
page: createPageSchema(),
|
||||
pageSize: createPageSizeSchema(20),
|
||||
search: z.string().trim().max(100).optional(),
|
||||
country: countryCodeSchema.optional(),
|
||||
plan: adminPlanFilterSchema.optional(),
|
||||
subscriptionStatus: adminSubscriptionFilterSchema.optional(),
|
||||
});
|
||||
export type AdminAccountQuery = z.output<typeof AdminAccountQuerySchema>;
|
||||
export type AdminAccountQueryInput = z.input<typeof AdminAccountQuerySchema>;
|
||||
|
||||
const AdminSubscriptionSummarySchema = z.object({
|
||||
status: subscriptionStatusSchema,
|
||||
amount: z.number(),
|
||||
currency: z.string(),
|
||||
paidThrough: isoDateTimeSchema.nullable(),
|
||||
nextPaymentDate: isoDateTimeSchema.nullable(),
|
||||
});
|
||||
|
||||
export const AdminAccountListItemSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
/** `null` until the professor picks one in the onboarding. */
|
||||
country: countryCodeSchema.nullable(),
|
||||
createdAt: isoDateTimeSchema,
|
||||
onboardingCompleted: z.boolean(),
|
||||
/** `null` while the professor has not chosen a plan. */
|
||||
plan: planSchema.nullable(),
|
||||
subscription: AdminSubscriptionSummarySchema.nullable(),
|
||||
groupsCount: z.number().int(),
|
||||
/** ACTIVE attendees across the groups the professor owns. */
|
||||
attendeesCount: z.number().int(),
|
||||
});
|
||||
export type AdminAccountListItem = z.output<typeof AdminAccountListItemSchema>;
|
||||
|
||||
export const AdminAccountListSchema = z.object({
|
||||
data: z.array(AdminAccountListItemSchema),
|
||||
pagination: createPaginationSchema(),
|
||||
});
|
||||
export type AdminAccountList = z.output<typeof AdminAccountListSchema>;
|
||||
|
||||
export const AdminAccountDetailSchema = AdminAccountListItemSchema.extend({
|
||||
planSelectedAt: isoDateTimeSchema.nullable(),
|
||||
/** Set while a lapsed Pro still works. */
|
||||
graceUntil: isoDateTimeSchema.nullable(),
|
||||
/** Free with more usage than its limits (only with BILLING_ENFORCEMENT on). */
|
||||
readOnly: z.boolean(),
|
||||
subscription: AdminSubscriptionSummarySchema.extend({
|
||||
payerEmail: z.string(),
|
||||
authorizedAt: isoDateTimeSchema.nullable(),
|
||||
requestedAt: isoDateTimeSchema,
|
||||
}).nullable(),
|
||||
mpStatus: z.enum(['ACTIVE', 'REQUIRES_REAUTH', 'REVOKED']).nullable(),
|
||||
whatsappStatus: z.enum(['PENDING', 'ACTIVE', 'DISCONNECTED']).nullable(),
|
||||
groups: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: isoDateTimeSchema,
|
||||
attendeesCount: z.number().int(),
|
||||
}),
|
||||
),
|
||||
charges: z.array(BillingChargeDtoSchema),
|
||||
});
|
||||
export type AdminAccountDetail = z.output<typeof AdminAccountDetailSchema>;
|
||||
Reference in New Issue
Block a user