refactor: remove unused attendee detail components and provider
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import type { PrismaClient } from '@generated/prisma/client';
|
||||
import type { AttendeeList, AttendeeQuery, ProblemDetails, Result } from '@gruperly/shared';
|
||||
import { ok } from '@gruperly/shared';
|
||||
import { ok, RECENT_ATTENDANCE_LIMIT } from '@gruperly/shared';
|
||||
import { getPaginationMetadata, getPaginationOffset } from '@/lib/pagination';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
import { type AttendeeRecord, toAttendeeDto } from '../../lib/helpers';
|
||||
import { toAttendeeListItemDto } from '../../lib/helpers';
|
||||
|
||||
type ListAttendeesDeps = {
|
||||
db?: Pick<PrismaClient, 'attendee'>;
|
||||
@@ -18,18 +18,37 @@ export class ListAttendees {
|
||||
const where = query.groupId ? { groupId: query.groupId } : undefined;
|
||||
|
||||
const [records, total] = await Promise.all([
|
||||
/* El resumen de cada fila viaja en la misma consulta en vez de armarse con
|
||||
una petición por miembro. Ambas relaciones vienen acotadas a propósito:
|
||||
la tabla de pagos crece un renglón por mes y para siempre, y el listado
|
||||
solo necesita el estado actual de cada persona. */
|
||||
db.attendee.findMany({
|
||||
...(where ? { where } : {}),
|
||||
skip: getPaginationOffset(query),
|
||||
take: query.pageSize,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
// Por fecha de la clase, no por `markedAt`: marcar la asistencia
|
||||
// tarde no debe cambiar qué clase cuenta como reciente.
|
||||
attendances: {
|
||||
orderBy: { classSession: { startsAt: 'desc' } },
|
||||
take: RECENT_ATTENDANCE_LIMIT,
|
||||
select: { status: true },
|
||||
},
|
||||
payments: {
|
||||
where: { status: { not: 'CANCELLED' } },
|
||||
orderBy: { dueDate: 'desc' },
|
||||
take: 3,
|
||||
select: { status: true, dueDate: true },
|
||||
},
|
||||
},
|
||||
}),
|
||||
where ? db.attendee.count({ where }) : db.attendee.count(),
|
||||
]);
|
||||
|
||||
return ok({
|
||||
data: records.map((r) => toAttendeeDto(r as AttendeeRecord)),
|
||||
data: records.map((record) => toAttendeeListItemDto(record)),
|
||||
pagination: getPaginationMetadata(query, total),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user