forked from wangziqi/gongxue-base
17 lines
633 B
TypeScript
17 lines
633 B
TypeScript
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
import type { Handler } from '../core/http.js';
|
|
import { RequestContextFactory } from './request-context.factory.js';
|
|
|
|
export abstract class DomainRouteService {
|
|
protected constructor(
|
|
protected readonly contextFactory: RequestContextFactory,
|
|
private readonly handlers: Record<string, Handler>,
|
|
) {}
|
|
|
|
execute(name: string, request: FastifyRequest, reply: FastifyReply) {
|
|
const handler = this.handlers[name];
|
|
if (!handler) throw new Error(`Missing domain route handler: ${name}`);
|
|
return handler(this.contextFactory.create(request, reply));
|
|
}
|
|
}
|