staff_data/apps/server/src/trpc/trpc.router.ts

45 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-07-11 11:00:51 +08:00
import { INestApplication, Injectable } from '@nestjs/common';
2024-09-10 10:31:24 +08:00
import { TransformRouter } from '@server/transform/transform.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-10 10:31:24 +08:00
import { TaxonomyRouter } from '@server/models/taxonomy/taxonomy.router';
import { TermRouter } from '@server/models/term/term.router';
import { RoleRouter } from '@server/rbac/role.router';
import { RoleMapRouter } from '@server/rbac/rolemap.router';
2024-07-11 11:00:51 +08:00
@Injectable()
export class TrpcRouter {
2024-09-10 10:31:24 +08:00
constructor(
private readonly trpc: TrpcService,
2024-09-03 20:29:51 +08:00
private readonly department: DepartmentRouter,
2024-09-10 10:31:24 +08:00
private readonly staff: StaffRouter,
private readonly term: TermRouter,
private readonly taxonomy: TaxonomyRouter,
private readonly role: RoleRouter,
private readonly rolemap: RoleMapRouter,
private readonly transform: TransformRouter,
2024-09-03 20:29:51 +08:00
) { }
2024-07-11 11:00:51 +08:00
appRouter = this.trpc.router({
2024-09-10 10:31:24 +08:00
transform: this.transform.router,
2024-09-03 20:29:51 +08:00
department: this.department.router,
2024-09-10 10:31:24 +08:00
staff: this.staff.router,
term: this.term.router,
taxonomy: this.taxonomy.router,
role: this.role.router,
rolemap: this.rolemap.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`];