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';
|
2025-02-06 16:32:52 +08:00
|
|
|
import { ResourceRouter } from '../models/resource/resource.router';
|
2025-03-11 16:15:05 +08:00
|
|
|
import { TrainContentRouter } from '@server/models/train-content/trainContent.router';
|
|
|
|
import { TrainSituationRouter } from '@server/models/train-situation/trainSituation.router';
|
2025-03-12 08:25:08 +08:00
|
|
|
import { DailyTrainRouter } from '@server/models/daily-train/dailyTrain.router';
|
2025-03-26 13:00:55 +08:00
|
|
|
import { SystemLogRouter } from '@server/models/sys-logs/systemLog.router';
|
2025-02-06 16:32:52 +08:00
|
|
|
|
2024-07-11 11:00:51 +08:00
|
|
|
@Injectable()
|
|
|
|
export class TrpcRouter {
|
2025-02-06 16:32:52 +08:00
|
|
|
logger = new Logger(TrpcRouter.name);
|
2024-12-30 08:26:40 +08:00
|
|
|
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,
|
2025-02-06 16:32:52 +08:00
|
|
|
private readonly resource: ResourceRouter,
|
2025-03-11 16:15:05 +08:00
|
|
|
private readonly trainContent: TrainContentRouter,
|
|
|
|
private readonly trainSituation:TrainSituationRouter,
|
2025-03-25 23:01:09 +08:00
|
|
|
private readonly dailyTrain:DailyTrainRouter,
|
2025-03-26 13:00:55 +08:00
|
|
|
private readonly systemLogRouter: SystemLogRouter,
|
2025-02-06 16:32:52 +08:00
|
|
|
) {}
|
|
|
|
getRouter() {
|
|
|
|
return;
|
|
|
|
}
|
2024-12-30 08:26:40 +08:00
|
|
|
appRouter = this.trpc.router({
|
|
|
|
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,
|
2025-02-06 16:32:52 +08:00
|
|
|
resource: this.resource.router,
|
2025-03-11 16:15:05 +08:00
|
|
|
trainContent:this.trainContent.router,
|
2025-03-12 08:25:08 +08:00
|
|
|
trainSituation:this.trainSituation.router,
|
2025-03-26 13:00:55 +08:00
|
|
|
dailyTrain:this.dailyTrain.router,
|
|
|
|
systemLog: this.systemLogRouter.router,
|
2024-12-30 08:26:40 +08:00
|
|
|
});
|
2025-02-06 16:32:52 +08:00
|
|
|
wss: WebSocketServer = undefined;
|
2024-12-30 08:26:40 +08:00
|
|
|
|
|
|
|
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);
|
2025-02-06 16:32:52 +08:00
|
|
|
},
|
2024-12-30 08:26:40 +08:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
// applyWSSHandler({
|
|
|
|
// wss: this.websocketService.getWss("trpc"),
|
|
|
|
// router: this.appRouter,
|
|
|
|
// createContext: this.trpc.createWSSContext,
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|