Renamed Student to Attendee
This commit is contained in:
18
apps/backend/src/modules/attendees/features/get-all/route.ts
Normal file
18
apps/backend/src/modules/attendees/features/get-all/route.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { AttendeeQuery } from '@gruperly/shared';
|
||||
import { AttendeeQuerySchema } from '@gruperly/shared';
|
||||
import { Hono } from 'hono';
|
||||
import { resultJson } from '@/http/problem-details';
|
||||
import { validate } from '@/http/validate';
|
||||
import { ListAttendees } from './use-case';
|
||||
|
||||
const route = new Hono();
|
||||
|
||||
route.get('/', validate.query(AttendeeQuerySchema), async (c) => {
|
||||
const query = c.req.valid('query') as AttendeeQuery;
|
||||
const useCase = new ListAttendees();
|
||||
const result: Awaited<ReturnType<typeof useCase.execute>> = await useCase.execute(query);
|
||||
|
||||
return resultJson(c, result);
|
||||
});
|
||||
|
||||
export default route;
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
}
|
||||
1
apps/backend/src/modules/attendees/index.ts
Normal file
1
apps/backend/src/modules/attendees/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as attendeesRoutes } from './routes';
|
||||
8
apps/backend/src/modules/attendees/routes.ts
Normal file
8
apps/backend/src/modules/attendees/routes.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Hono } from 'hono';
|
||||
import getAllRoute from './features/get-all/route';
|
||||
|
||||
const routes = new Hono();
|
||||
|
||||
routes.route('/', getAllRoute);
|
||||
|
||||
export default routes;
|
||||
Reference in New Issue
Block a user