refactor: migrate backend to pnpm monorepo with Hono module architecture
- Replace Bun with pnpm 9 + Turborepo + tsx; apps/api renamed to apps/backend - Split backend into http/, modules/, lib/ layers mirroring tai-specguard - Add use-case + Result pattern, Problem Details RFC 7807, basePath /api/v1 - Mount Better Auth at /api/v1/auth, keep session-auth whitelist - Split Prisma schema into prisma/models/*, generate into generated/ - Rework packages/shared into lib/ + schemas/ with pagination DTOs - Implement health, groups, students, payments, waitlist modules - Add vitest suite with prisma mocks (21 tests), biome lint - Point web client to /api/v1/auth and /api/v1/groups/from-organization
This commit is contained in:
18
apps/backend/src/modules/waitlist/features/get-all/route.ts
Normal file
18
apps/backend/src/modules/waitlist/features/get-all/route.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { WaitlistQuery } from '@gruperly/shared';
|
||||
import { WaitlistQuerySchema } from '@gruperly/shared';
|
||||
import { Hono } from 'hono';
|
||||
import { resultJson } from '@/http/problem-details';
|
||||
import { validate } from '@/http/validate';
|
||||
import { ListWaitlistEntries } from './use-case';
|
||||
|
||||
const route = new Hono();
|
||||
|
||||
route.get('/', validate.query(WaitlistQuerySchema), async (c) => {
|
||||
const query = c.req.valid('query') as WaitlistQuery;
|
||||
const useCase = new ListWaitlistEntries();
|
||||
const result = await useCase.execute(query);
|
||||
|
||||
return resultJson(c, result);
|
||||
});
|
||||
|
||||
export default route;
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { PrismaClient } from '@generated/prisma/client';
|
||||
import type { ProblemDetails, Result, WaitlistEntryDto, WaitlistList, WaitlistQuery } from '@gruperly/shared';
|
||||
import { ok } from '@gruperly/shared';
|
||||
import { getPaginationMetadata, getPaginationOffset } from '@/lib/pagination';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
type ListWaitlistEntriesDeps = {
|
||||
db?: Pick<PrismaClient, 'waitlistEntry'>;
|
||||
};
|
||||
|
||||
type WaitlistRecord = {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
status: WaitlistEntryDto['status'];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
|
||||
function toWaitlistEntryDto(record: WaitlistRecord): WaitlistEntryDto {
|
||||
return {
|
||||
id: record.id,
|
||||
email: record.email,
|
||||
name: record.name,
|
||||
status: record.status,
|
||||
createdAt: record.createdAt.toISOString(),
|
||||
updatedAt: record.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
export class ListWaitlistEntries {
|
||||
constructor(private readonly deps: ListWaitlistEntriesDeps = {}) {}
|
||||
|
||||
async execute(query: WaitlistQuery): Promise<Result<WaitlistList, ProblemDetails>> {
|
||||
const db = this.deps.db ?? prisma;
|
||||
const [records, total] = await Promise.all([
|
||||
db.waitlistEntry.findMany({
|
||||
skip: getPaginationOffset(query),
|
||||
take: query.pageSize,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
db.waitlistEntry.count(),
|
||||
]);
|
||||
|
||||
return ok({
|
||||
data: records.map(toWaitlistEntryDto),
|
||||
pagination: getPaginationMetadata(query, total),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user