feat: manage waitlist and remove group members
- Add group-waitlist module (list/promote/remove entries) - Remove attendee with optional atomic promotion from waitlist - Block removal when attendee has payments (attendee_has_payments) - Waitlist detail modal matching members UI; optimistic add-to-waitlist - Responsive tweaks for the members/waitlist tabs
This commit is contained in:
65
apps/backend/src/modules/group-waitlist/lib/helpers.ts
Normal file
65
apps/backend/src/modules/group-waitlist/lib/helpers.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { Group, PrismaClient } from '@generated/prisma/client';
|
||||
import type { GroupWaitlistEntryDto, ProblemDetails, Result } from '@gruperly/shared';
|
||||
import { err, ok } from '@gruperly/shared';
|
||||
import { noGroupAccessProblem, notFoundResourceProblem } from '@/http/problem-builders';
|
||||
|
||||
export type GroupWaitlistEntryRecord = {
|
||||
id: string;
|
||||
groupId: string;
|
||||
fullName: string;
|
||||
phone: string;
|
||||
email: string | null;
|
||||
notes: string | null;
|
||||
status: GroupWaitlistEntryDto['status'];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
|
||||
export function toGroupWaitlistEntryDto(record: GroupWaitlistEntryRecord): GroupWaitlistEntryDto {
|
||||
return {
|
||||
id: record.id,
|
||||
groupId: record.groupId,
|
||||
fullName: record.fullName,
|
||||
phone: record.phone,
|
||||
email: record.email,
|
||||
notes: record.notes,
|
||||
status: record.status,
|
||||
createdAt: record.createdAt.toISOString(),
|
||||
updatedAt: record.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
export async function findGroupForUser(
|
||||
db: Pick<PrismaClient, 'group'>,
|
||||
groupId: string,
|
||||
userId: string,
|
||||
): Promise<Result<Group, ProblemDetails>> {
|
||||
const group = await db.group.findUnique({
|
||||
where: { id: groupId },
|
||||
include: { members: { where: { userId } } },
|
||||
});
|
||||
if (!group) {
|
||||
return err(notFoundResourceProblem('Group', groupId));
|
||||
}
|
||||
const isOwner = group.createdById === userId;
|
||||
const isMember = group.members.length > 0;
|
||||
if (!isOwner && !isMember) {
|
||||
return err(noGroupAccessProblem());
|
||||
}
|
||||
return ok(group);
|
||||
}
|
||||
|
||||
export async function findGroupOwnedByUser(
|
||||
db: Pick<PrismaClient, 'group'>,
|
||||
groupId: string,
|
||||
userId: string,
|
||||
): Promise<Result<Group, ProblemDetails>> {
|
||||
const group = await db.group.findUnique({ where: { id: groupId } });
|
||||
if (!group) {
|
||||
return err(notFoundResourceProblem('Group', groupId));
|
||||
}
|
||||
if (group.createdById !== userId) {
|
||||
return err(noGroupAccessProblem());
|
||||
}
|
||||
return ok(group);
|
||||
}
|
||||
Reference in New Issue
Block a user