feat: filtro de grupo en cobros con cuotas pendientes por grupo
- El listado de grupos devuelve `unpaidPaymentsCount` (PENDING y OVERDUE). - Cobros: nuevo selector de grupo (GroupFilter) junto a los filtros de estado; con un grupo filtrado no se repite su nombre en cada card. - Sheet: entra deslizando desde abajo en mobile (salvo reduced motion). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,13 +21,15 @@ type ListGroupsDeps = {
|
||||
now?: Date;
|
||||
};
|
||||
|
||||
const OCCUPANCY_COUNT_INCLUDE = {
|
||||
const LIST_COUNT_INCLUDE = {
|
||||
_count: {
|
||||
select: {
|
||||
// Group members. No status filter, same as the detail page counts.
|
||||
attendees: true,
|
||||
// Waitlist: the ones still waiting for a spot (the reviewed ones drop out).
|
||||
waitlist: { where: { status: 'PENDING' as const } },
|
||||
// Payments still to collect: the ones pending and the overdue ones.
|
||||
payments: { where: { status: { in: ['PENDING' as const, 'OVERDUE' as const] } } },
|
||||
},
|
||||
},
|
||||
} satisfies Prisma.GroupInclude;
|
||||
@@ -49,7 +51,7 @@ export class ListGroups {
|
||||
// time zone (or the server's if it doesn't come along).
|
||||
const records: GroupListRecord[] = await db.group.findMany({
|
||||
where,
|
||||
include: OCCUPANCY_COUNT_INCLUDE,
|
||||
include: LIST_COUNT_INCLUDE,
|
||||
});
|
||||
|
||||
const timeZone = query.timeZone ?? DEFAULT_TIME_ZONE;
|
||||
|
||||
@@ -26,9 +26,10 @@ export type GroupRecord = {
|
||||
/* The listing adds the occupancy counters to each group so the card can show
|
||||
them without asking for one endpoint per group. They come from the `_count` of
|
||||
the same query: all the members (same as the detail page counts) and only the
|
||||
waitlist entries still waiting for a spot (PENDING). */
|
||||
waitlist entries still waiting for a spot (PENDING), plus the payments still
|
||||
to collect (PENDING and OVERDUE). */
|
||||
export type GroupListRecord = GroupRecord & {
|
||||
_count?: { attendees: number; waitlist: number };
|
||||
_count?: { attendees: number; waitlist: number; payments?: number };
|
||||
};
|
||||
|
||||
export function toGroupDto(record: GroupRecord): GroupDto {
|
||||
@@ -56,6 +57,7 @@ export function toGroupListItemDto(record: GroupListRecord): GroupListItem {
|
||||
...toGroupDto(record),
|
||||
attendeesCount: record._count?.attendees ?? 0,
|
||||
waitlistCount: record._count?.waitlist ?? 0,
|
||||
unpaidPaymentsCount: record._count?.payments ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('groups routes', () => {
|
||||
|
||||
it('lists groups scoped to the current user', async () => {
|
||||
prisma.group.findMany.mockResolvedValue([
|
||||
{ ...group, _count: { attendees: 4, waitlist: 1 } },
|
||||
{ ...group, _count: { attendees: 4, waitlist: 1, payments: 3 } },
|
||||
]);
|
||||
prisma.group.count.mockResolvedValue(1);
|
||||
|
||||
@@ -76,6 +76,7 @@ describe('groups routes', () => {
|
||||
updatedAt: group.updatedAt.toISOString(),
|
||||
attendeesCount: 4,
|
||||
waitlistCount: 1,
|
||||
unpaidPaymentsCount: 3,
|
||||
},
|
||||
],
|
||||
pagination: { page: 1, pageSize: 10, total: 1, totalPages: 1 },
|
||||
@@ -89,7 +90,11 @@ describe('groups routes', () => {
|
||||
where,
|
||||
include: {
|
||||
_count: {
|
||||
select: { attendees: true, waitlist: { where: { status: 'PENDING' } } },
|
||||
select: {
|
||||
attendees: true,
|
||||
waitlist: { where: { status: 'PENDING' } },
|
||||
payments: { where: { status: { in: ['PENDING', 'OVERDUE'] } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user