Files
gruperly/packages/shared/src/schemas/payments.ts
Jose Selesan cb872eb8bc feat: soporte multi idioma en la web (infraestructura)
i18next + react-i18next con es-AR (fuente), es-419, pt-BR y en; el idioma
sale del dispositivo (fallback a inglés) y se puede cambiar en Ajustes.
La elección se guarda en localStorage y, para el profe, en users.locale.
Las validaciones de shared pasan a claves y los errores de la API se
traducen por code (con params para límites de plan y cupo).
Migrados: layout, Ajustes, auth, PWA y lib/format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 12:14:59 -03:00

74 lines
2.6 KiB
TypeScript

import { z } from 'zod';
import { createPageSchema, createPageSizeSchema, createPaginationSchema } from './pagination.js';
const isoDateTimeSchema = z.string().datetime();
const pageSchema = createPageSchema();
const pageSizeSchema = createPageSizeSchema(10);
const paginationSchema = createPaginationSchema();
export const paymentStatusSchema = z.enum(['PENDING', 'PAID', 'OVERDUE', 'CANCELLED']);
export type PaymentStatus = z.output<typeof paymentStatusSchema>;
export const PaymentDtoSchema = z.object({
id: z.string(),
groupId: z.string(),
groupName: z.string(),
attendeeId: z.string(),
attendeeName: z.string(),
amount: z.coerce.number().positive(),
currency: z.string(),
status: paymentStatusSchema,
description: z.string().nullable(),
checkoutUrl: z.string().nullable(),
dueDate: isoDateTimeSchema,
paidAt: isoDateTimeSchema.nullable(),
createdAt: isoDateTimeSchema,
updatedAt: isoDateTimeSchema,
});
export type PaymentDto = z.output<typeof PaymentDtoSchema>;
export const PaymentQuerySchema = z.object({
page: pageSchema,
pageSize: pageSizeSchema,
groupId: z.string().min(1).optional(),
status: paymentStatusSchema.optional(),
});
export type PaymentQuery = z.output<typeof PaymentQuerySchema>;
export const PaymentListSchema = z.object({
data: z.array(PaymentDtoSchema),
pagination: paginationSchema,
});
export type PaymentList = z.output<typeof PaymentListSchema>;
// Creates one payment link per active attendee of a group. The professor
// triggers it from the group page for a period (e.g. June's monthly fee).
export const CreatePaymentsBatchSchema = z.strictObject({
dueDate: isoDateTimeSchema,
description: z.string().trim().max(120, 'payment.descriptionMax').optional(),
attendeeIds: z.array(z.string().min(1)).min(1).optional(),
});
export type CreatePaymentsBatch = z.output<typeof CreatePaymentsBatchSchema>;
export const paymentBatchOutcomeSchema = z.enum(['CREATED', 'LINKED', 'FAILED']);
export const PaymentBatchItemSchema = z.object({
paymentId: z.string(),
attendeeId: z.string(),
attendeeName: z.string(),
amount: z.number().positive(),
currency: z.string(),
checkoutUrl: z.string().nullable(),
outcome: paymentBatchOutcomeSchema,
reason: z.string().nullable(),
});
export type PaymentBatchItem = z.output<typeof PaymentBatchItemSchema>;
export const CreatePaymentsBatchResultSchema = z.object({
groupId: z.string(),
total: z.number().int().min(0),
linked: z.number().int().min(0),
failed: z.number().int().min(0),
items: z.array(PaymentBatchItemSchema),
});
export type CreatePaymentsBatchResult = z.output<typeof CreatePaymentsBatchResultSchema>;