feat: add reserved turns management for generals and nations; enhance command selection UI
This commit is contained in:
@@ -6,6 +6,8 @@ import { buildTurnCommandTable } from '../../turns/commandTable.js';
|
||||
import {
|
||||
MAX_GENERAL_TURNS,
|
||||
MAX_NATION_TURNS,
|
||||
listGeneralTurns,
|
||||
listNationTurns,
|
||||
setGeneralTurn,
|
||||
setNationTurn,
|
||||
shiftGeneralTurns,
|
||||
@@ -76,6 +78,56 @@ export const turnsRouter = router({
|
||||
});
|
||||
}),
|
||||
reserved: router({
|
||||
getGeneral: authedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
generalId: z.number().int().positive(),
|
||||
})
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const general = await ctx.db.general.findUnique({
|
||||
where: { id: input.generalId },
|
||||
});
|
||||
if (!general) {
|
||||
throw new TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: 'General not found.',
|
||||
});
|
||||
}
|
||||
|
||||
return listGeneralTurns(ctx.db, input.generalId);
|
||||
}),
|
||||
getNation: authedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
generalId: z.number().int().positive(),
|
||||
})
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const general = await ctx.db.general.findUnique({
|
||||
where: { id: input.generalId },
|
||||
});
|
||||
if (!general) {
|
||||
throw new TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: 'General not found.',
|
||||
});
|
||||
}
|
||||
if (general.nationId <= 0) {
|
||||
throw new TRPCError({
|
||||
code: 'PRECONDITION_FAILED',
|
||||
message: 'General is not part of a nation.',
|
||||
});
|
||||
}
|
||||
if (general.officerLevel < 5) {
|
||||
throw new TRPCError({
|
||||
code: 'FORBIDDEN',
|
||||
message: 'General is not an officer.',
|
||||
});
|
||||
}
|
||||
|
||||
return listNationTurns(ctx.db, general.nationId, general.officerLevel);
|
||||
}),
|
||||
setGeneral: authedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
|
||||
@@ -108,6 +108,11 @@ export const loadGeneralTurns = async (db: DatabaseClient, generalId: number): P
|
||||
return buildTurnListFromRows(rows, MAX_GENERAL_TURNS);
|
||||
};
|
||||
|
||||
export const listGeneralTurns = async (db: DatabaseClient, generalId: number): Promise<ReservedTurnView[]> => {
|
||||
const turns = await loadGeneralTurns(db, generalId);
|
||||
return serializeTurnList(turns);
|
||||
};
|
||||
|
||||
export const loadNationTurns = async (
|
||||
db: DatabaseClient,
|
||||
nationId: number,
|
||||
@@ -120,6 +125,15 @@ export const loadNationTurns = async (
|
||||
return buildTurnListFromRows(rows, MAX_NATION_TURNS);
|
||||
};
|
||||
|
||||
export const listNationTurns = async (
|
||||
db: DatabaseClient,
|
||||
nationId: number,
|
||||
officerLevel: number
|
||||
): Promise<ReservedTurnView[]> => {
|
||||
const turns = await loadNationTurns(db, nationId, officerLevel);
|
||||
return serializeTurnList(turns);
|
||||
};
|
||||
|
||||
export const setGeneralTurn = async (
|
||||
db: DatabaseClient,
|
||||
generalId: number,
|
||||
|
||||
Reference in New Issue
Block a user