router 분리

This commit is contained in:
2026-01-16 18:06:51 +00:00
parent 998035c66c
commit f3591612fa
13 changed files with 1440 additions and 1368 deletions
+73
View File
@@ -0,0 +1,73 @@
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import { authedProcedure, router } from '../../trpc.js';
export const troopRouter = router({
join: authedProcedure
.input(
z.object({
generalId: z.number().int().positive(),
troopId: z.number().int().positive(),
})
)
.mutation(async ({ ctx, input }) => {
const result = await ctx.turnDaemon.requestCommand({
type: 'troopJoin',
generalId: input.generalId,
troopId: input.troopId,
});
if (!result) {
throw new TRPCError({
code: 'TIMEOUT',
message: 'Turn daemon did not respond.',
});
}
if (result.type !== 'troopJoin') {
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: 'Unexpected turn daemon response.',
});
}
if (!result.ok) {
throw new TRPCError({
code: 'PRECONDITION_FAILED',
message: result.reason,
});
}
return { ok: true };
}),
exit: authedProcedure
.input(
z.object({
generalId: z.number().int().positive(),
})
)
.mutation(async ({ ctx, input }) => {
const result = await ctx.turnDaemon.requestCommand({
type: 'troopExit',
generalId: input.generalId,
});
if (!result) {
throw new TRPCError({
code: 'TIMEOUT',
message: 'Turn daemon did not respond.',
});
}
if (result.type !== 'troopExit') {
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: 'Unexpected turn daemon response.',
});
}
if (!result.ok) {
throw new TRPCError({
code: 'PRECONDITION_FAILED',
message: result.reason,
});
}
return { ok: true, wasLeader: result.wasLeader };
}),
});