feat(spa): guard angular host/player api contracts
CI / test-and-quality (push) Successful in 2m22s
CI / test-and-quality (pull_request) Successful in 1m56s

This commit is contained in:
2026-03-01 16:40:34 +00:00
parent 9a69110c7d
commit fb782432ea
4 changed files with 527 additions and 3 deletions
+131 -2
View File
@@ -1,18 +1,36 @@
import {
mapCalculateScoresResponse,
mapFinishGameResponse,
mapHealthResponse,
mapJoinSessionResponse,
mapMixAnswersResponse,
mapScoreboardResponse,
mapSessionDetailResponse,
mapStartRoundResponse
mapShowQuestionResponse,
mapStartNextRoundResponse,
mapStartRoundResponse,
mapSubmitGuessResponse,
mapSubmitLieResponse
} from './mappers';
import type {
ApiFailure,
ApiResult,
CalculateScoresResponse,
FinishGameResponse,
HealthResponse,
JoinSessionRequest,
JoinSessionResponse,
MixAnswersResponse,
ScoreboardResponse,
SessionDetailResponse,
ShowQuestionResponse,
StartNextRoundResponse,
StartRoundRequest,
StartRoundResponse
StartRoundResponse,
SubmitGuessRequest,
SubmitGuessResponse,
SubmitLieRequest,
SubmitLieResponse
} from './types';
export interface AngularHttpError {
@@ -31,6 +49,18 @@ export interface AngularApiClient {
getSession(code: string): Promise<ApiResult<SessionDetailResponse>>;
joinSession(payload: JoinSessionRequest): Promise<ApiResult<JoinSessionResponse>>;
startRound(code: string, payload: StartRoundRequest): Promise<ApiResult<StartRoundResponse>>;
showQuestion(code: string): Promise<ApiResult<ShowQuestionResponse>>;
mixAnswers(code: string, roundQuestionId: number): Promise<ApiResult<MixAnswersResponse>>;
calculateScores(code: string, roundQuestionId: number): Promise<ApiResult<CalculateScoresResponse>>;
getScoreboard(code: string): Promise<ApiResult<ScoreboardResponse>>;
startNextRound(code: string): Promise<ApiResult<StartNextRoundResponse>>;
finishGame(code: string): Promise<ApiResult<FinishGameResponse>>;
submitLie(code: string, roundQuestionId: number, payload: SubmitLieRequest): Promise<ApiResult<SubmitLieResponse>>;
submitGuess(
code: string,
roundQuestionId: number,
payload: SubmitGuessRequest
): Promise<ApiResult<SubmitGuessResponse>>;
}
function toFailure(error: unknown): ApiFailure {
@@ -128,6 +158,105 @@ export function createAngularApiClient(http: AngularHttpClientLike, baseUrl = ''
{ withCredentials: true }
),
mapStartRoundResponse
),
showQuestion: (code: string) =>
wrap(
() =>
http.post<ShowQuestionResponse>(
buildUrl(baseUrl, `/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/questions/show`),
{},
{ withCredentials: true }
),
mapShowQuestionResponse
),
mixAnswers: (code: string, roundQuestionId: number) =>
wrap(
() =>
http.post<MixAnswersResponse>(
buildUrl(
baseUrl,
`/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/questions/${roundQuestionId}/answers/mix`
),
{},
{ withCredentials: true }
),
mapMixAnswersResponse
),
calculateScores: (code: string, roundQuestionId: number) =>
wrap(
() =>
http.post<CalculateScoresResponse>(
buildUrl(
baseUrl,
`/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/questions/${roundQuestionId}/scores/calculate`
),
{},
{ withCredentials: true }
),
mapCalculateScoresResponse
),
getScoreboard: (code: string) =>
wrap(
() =>
http.get<ScoreboardResponse>(
buildUrl(baseUrl, `/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/scoreboard`),
{ withCredentials: true }
),
mapScoreboardResponse
),
startNextRound: (code: string) =>
wrap(
() =>
http.post<StartNextRoundResponse>(
buildUrl(baseUrl, `/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/rounds/next`),
{},
{ withCredentials: true }
),
mapStartNextRoundResponse
),
finishGame: (code: string) =>
wrap(
() =>
http.post<FinishGameResponse>(
buildUrl(baseUrl, `/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/finish`),
{},
{ withCredentials: true }
),
mapFinishGameResponse
),
submitLie: (code: string, roundQuestionId: number, payload: SubmitLieRequest) =>
wrap(
() =>
http.post<SubmitLieResponse>(
buildUrl(
baseUrl,
`/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/questions/${roundQuestionId}/lies/submit`
),
{
player_id: payload.player_id,
session_token: payload.session_token,
text: payload.text
},
{ withCredentials: true }
),
mapSubmitLieResponse
),
submitGuess: (code: string, roundQuestionId: number, payload: SubmitGuessRequest) =>
wrap(
() =>
http.post<SubmitGuessResponse>(
buildUrl(
baseUrl,
`/lobby/sessions/${encodeURIComponent(normalizeCode(code))}/questions/${roundQuestionId}/guesses/submit`
),
{
player_id: payload.player_id,
session_token: payload.session_token,
selected_text: payload.selected_text
},
{ withCredentials: true }
),
mapSubmitGuessResponse
)
};
}