doctor-mail/apps/server/src/trpc/trpc.router.ts

35 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-07-11 11:00:51 +08:00
import { INestApplication, Injectable } from '@nestjs/common';
2024-09-03 20:19:33 +08:00
import { AuthRouter } from '@server/auth/auth.router';
2024-09-03 20:29:51 +08:00
import { DepartmentRouter } from '@server/models/department/department.router';
import { StaffRouter } from '@server/models/staff/staff.router';
2024-07-11 11:00:51 +08:00
import { TrpcService } from '@server/trpc/trpc.service';
import * as trpcExpress from '@trpc/server/adapters/express';
2024-09-03 20:29:51 +08:00
import { TransformRouter } from '../transform/transform.router';
2024-07-11 11:00:51 +08:00
@Injectable()
export class TrpcRouter {
2024-09-03 20:29:51 +08:00
constructor(private readonly trpc: TrpcService,
private readonly auth: AuthRouter,
private readonly staff: StaffRouter,
private readonly department: DepartmentRouter,
private readonly transform: TransformRouter
) { }
2024-07-11 11:00:51 +08:00
appRouter = this.trpc.router({
2024-09-03 20:29:51 +08:00
auth: this.auth.router,
staff: this.staff.router,
department: this.department.router,
transform: this.transform.router
2024-07-11 11:00:51 +08:00
});
async applyMiddleware(app: INestApplication) {
app.use(
`/trpc`,
trpcExpress.createExpressMiddleware({
router: this.appRouter,
2024-09-03 20:19:33 +08:00
createContext: this.trpc.createContext
2024-07-11 11:00:51 +08:00
}),
);
}
}
export type AppRouter = TrpcRouter[`appRouter`];