Renamed Student to Attendee

This commit is contained in:
Jose Selesan
2026-09-17 18:58:00 -03:00
parent e8bca3a5ae
commit fa30fe2cff
22 changed files with 120 additions and 104 deletions

View File

@@ -0,0 +1,58 @@
import type { PrismaClient } from '@generated/prisma/client';
import type { AttendeeDto, AttendeeList, AttendeeQuery, ProblemDetails, Result } from '@gruperly/shared';
import { ok } from '@gruperly/shared';
import { getPaginationMetadata, getPaginationOffset } from '@/lib/pagination';
import prisma from '@/lib/prisma';
type ListAttendeesDeps = {
db?: Pick<PrismaClient, 'attendee'>;
};
type AttendeeRecord = {
id: string;
groupId: string;
fullName: string;
email: string | null;
phone: string | null;
guardianName: string | null;
guardianPhone: string | null;
notes: string | null;
createdAt: Date;
updatedAt: Date;
};
function toAttendeeDto(record: AttendeeRecord): AttendeeDto {
return {
id: record.id,
groupId: record.groupId,
fullName: record.fullName,
email: record.email,
phone: record.phone,
guardianName: record.guardianName,
guardianPhone: record.guardianPhone,
notes: record.notes,
createdAt: record.createdAt.toISOString(),
updatedAt: record.updatedAt.toISOString(),
};
}
export class ListAttendees {
constructor(private readonly deps: ListAttendeesDeps = {}) {}
async execute(query: AttendeeQuery): Promise<Result<AttendeeList, ProblemDetails>> {
const db = this.deps.db ?? prisma;
const [records, total] = await Promise.all([
db.attendee.findMany({
skip: getPaginationOffset(query),
take: query.pageSize,
orderBy: { createdAt: 'desc' },
}),
db.attendee.count(),
]);
return ok({
data: records.map(toAttendeeDto),
pagination: getPaginationMetadata(query, total),
});
}
}