Added shome shit to invert who is home and away.
This commit is contained in:
1 parent
3bc18baa30
commit
514bb0ac47
3 files changed
+40
No files matched your search
@@ -187,6 +187,25 @@ memberRouter.post("/games/:gameId", async (ctx) => {
|
|||||||
: `<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>`;
|
: `<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
memberRouter.post("/games/:gameId/switch", async (ctx) => {
|
||||||
|
if (!(await loginService.isLoggedIn(ctx))) {
|
||||||
|
ctx.response.redirect("/membre");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const success = await gameService.switchVisitors(ctx.params.gameId);
|
||||||
|
if (!success) {
|
||||||
|
ctx.response.body = `<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>`;
|
||||||
|
}
|
||||||
|
const template = await env.load("templates/partials/single-game-editor.vto");
|
||||||
|
const game = await gameService.getGameById(ctx.params.gameId);
|
||||||
|
const result = await template({
|
||||||
|
tab: "membre",
|
||||||
|
game: game,
|
||||||
|
});
|
||||||
|
ctx.response.headers.set("game-id", game?.id ?? "");
|
||||||
|
ctx.response.body = result.content;
|
||||||
|
});
|
||||||
|
|
||||||
const apiRouter = new Router();
|
const apiRouter = new Router();
|
||||||
|
|
||||||
apiRouter.get("/results/:year.json", async (ctx) => {
|
apiRouter.get("/results/:year.json", async (ctx) => {
|
||||||
|
|||||||
@@ -173,6 +173,23 @@ export class GameService {
|
|||||||
return res.ok;
|
return res.ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async switchVisitors(id: string): Promise<boolean> {
|
||||||
|
const game = await this.getGameById(id);
|
||||||
|
if (game === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
delete game.id;
|
||||||
|
const [home, away] = [game.home, game.away];
|
||||||
|
const [homeScore, awayScore] = [game.homeScore, game.awayScore];
|
||||||
|
game.home = away;
|
||||||
|
game.away = home;
|
||||||
|
game.homeScore = awayScore;
|
||||||
|
game.awayScore = homeScore;
|
||||||
|
console.log(`game ${game}`);
|
||||||
|
|
||||||
|
return this.updateGame(id, game);
|
||||||
|
}
|
||||||
|
|
||||||
async updateGame(id: string, partial: Partial<Game>): Promise<boolean> {
|
async updateGame(id: string, partial: Partial<Game>): Promise<boolean> {
|
||||||
delete partial.id;
|
delete partial.id;
|
||||||
const precond = await this.kv.get<Game>(this.gamePrimaryKey(id));
|
const precond = await this.kv.get<Game>(this.gamePrimaryKey(id));
|
||||||
|
|||||||
@@ -58,6 +58,10 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div style="text-align: right">
|
<div style="text-align: right">
|
||||||
|
<button class="uk-button"
|
||||||
|
hx-post="/membre/games/{{game.id}}/switch"
|
||||||
|
hx-target="#game-{{ game.id }}"
|
||||||
|
>Inverser visiteur/receveur</button>
|
||||||
<button class="uk-button-danger"
|
<button class="uk-button-danger"
|
||||||
hx-delete="/membre/games/{{game.id}}"
|
hx-delete="/membre/games/{{game.id}}"
|
||||||
hx-confirm="Certain de vouloir supprimer la partie?"
|
hx-confirm="Certain de vouloir supprimer la partie?"
|
||||||
|
|||||||
Reference in new issue
Block a user