Files
gruperly/apps/backend/src/modules/groups/lib/helpers.ts
Jose Selesan d397e9663c 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>
2026-11-02 14:59:33 -03:00

71 lines
2.2 KiB
TypeScript

import type { PrismaClient } from '@generated/prisma/client';
import type { BillingType, GroupDto, GroupListItem, WeekDay } from '@gruperly/shared';
export type GroupDb = Pick<PrismaClient, 'group' | 'groupMember'>;
type PriceLike = { toString(): string };
export type GroupRecord = {
id: string;
name: string;
description: string | null;
createdById: string;
createdAt: Date;
updatedAt: Date;
days: WeekDay[] | null;
time: string | null;
capacity: number | null;
price: PriceLike | number | null;
billingType: BillingType | null;
dueDay: number | null;
inviteToken?: string | null;
autoPaymentReminders?: boolean;
autoReengagement?: boolean;
};
/* 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), plus the payments still
to collect (PENDING and OVERDUE). */
export type GroupListRecord = GroupRecord & {
_count?: { attendees: number; waitlist: number; payments?: number };
};
export function toGroupDto(record: GroupRecord): GroupDto {
return {
id: record.id,
name: record.name,
description: record.description,
createdById: record.createdById,
createdAt: record.createdAt.toISOString(),
updatedAt: record.updatedAt.toISOString(),
days: record.days,
time: record.time,
capacity: record.capacity,
price: record.price == null ? null : Number(record.price.toString()),
billingType: record.billingType,
dueDay: record.dueDay,
inviteToken: record.inviteToken ?? null,
autoPaymentReminders: record.autoPaymentReminders ?? false,
autoReengagement: record.autoReengagement ?? false,
};
}
export function toGroupListItemDto(record: GroupListRecord): GroupListItem {
return {
...toGroupDto(record),
attendeesCount: record._count?.attendees ?? 0,
waitlistCount: record._count?.waitlist ?? 0,
unpaidPaymentsCount: record._count?.payments ?? 0,
};
}
export function buildGroupWhereForUser(userId: string) {
return {
OR: [
{ createdById: userId },
{ members: { some: { userId } } },
],
};
}