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

79 lines
3.1 KiB
TypeScript
Raw Normal View History

2024-12-30 08:26:40 +08:00
import { INestApplication, Injectable, Logger } from '@nestjs/common';
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-09-10 10:31:24 +08:00
import { TaxonomyRouter } from '@server/models/taxonomy/taxonomy.router';
import { TermRouter } from '@server/models/term/term.router';
2024-12-30 08:26:40 +08:00
import { TrpcService } from '@server/trpc/trpc.service';
import * as trpcExpress from '@trpc/server/adapters/express';
import ws, { WebSocketServer } from 'ws';
import { AppConfigRouter } from '@server/models/app-config/app-config.router';
import { MessageRouter } from '@server/models/message/message.router';
import { PostRouter } from '@server/models/post/post.router';
import { VisitRouter } from '@server/models/visit/visit.router';
import { RoleMapRouter } from '@server/models/rbac/rolemap.router';
import { TransformRouter } from '@server/models/transform/transform.router';
import { RoleRouter } from '@server/models/rbac/role.router';
2024-12-31 15:57:32 +08:00
import { CourseRouter } from '@server/models/course/course.router';
import { LectureRouter } from '@server/models/lecture/lecture.router';
import { SectionRouter } from '@server/models/section/section.router';
2024-07-11 11:00:51 +08:00
@Injectable()
export class TrpcRouter {
2024-12-30 08:26:40 +08:00
logger = new Logger(TrpcRouter.name)
constructor(
private readonly trpc: TrpcService,
private readonly post: PostRouter,
private readonly department: DepartmentRouter,
private readonly staff: StaffRouter,
private readonly term: TermRouter,
private readonly taxonomy: TaxonomyRouter,
private readonly role: RoleRouter,
private readonly rolemap: RoleMapRouter,
private readonly transform: TransformRouter,
private readonly app_config: AppConfigRouter,
private readonly message: MessageRouter,
private readonly visitor: VisitRouter,
2024-12-31 15:57:32 +08:00
private readonly course: CourseRouter,
private readonly lecture: LectureRouter,
private readonly section: SectionRouter
2024-12-30 08:26:40 +08:00
// private readonly websocketService: WebSocketService
) { }
appRouter = this.trpc.router({
2025-01-03 09:24:46 +08:00
2024-12-30 08:26:40 +08:00
transform: this.transform.router,
post: this.post.router,
department: this.department.router,
staff: this.staff.router,
term: this.term.router,
taxonomy: this.taxonomy.router,
role: this.role.router,
rolemap: this.rolemap.router,
message: this.message.router,
app_config: this.app_config.router,
2024-12-31 15:57:32 +08:00
visitor: this.visitor.router,
course: this.course.router,
lecture: this.lecture.router,
section: this.section.router
2024-12-30 08:26:40 +08:00
});
wss: WebSocketServer = undefined
async applyMiddleware(app: INestApplication) {
app.use(
`/trpc`,
trpcExpress.createExpressMiddleware({
router: this.appRouter,
createContext: this.trpc.createExpressContext,
onError(opts) {
const { error, type, path, input, ctx, req } = opts;
// console.error('TRPC Error:', error);
}
}),
);
// applyWSSHandler({
// wss: this.websocketService.getWss("trpc"),
// router: this.appRouter,
// createContext: this.trpc.createWSSContext,
// });
}
}
2024-07-11 11:00:51 +08:00
export type AppRouter = TrpcRouter[`appRouter`];