refacto : gameFromUrl

This commit is contained in:
GuillaumeSD
2024-02-23 23:32:29 +01:00
parent f77a425067
commit 89ca7d8f13
9 changed files with 105 additions and 31 deletions

View File

@@ -26,3 +26,26 @@ export const formatGameToDatabase = (game: Chess): Omit<Game, "id"> => {
result: headers.Result,
};
};
export const getGameToSave = (game: Chess, board: Chess): Chess => {
if (game.history().length) return game;
const headers = board.header();
if (!headers.Event) {
board.header("Event", "Freechess Game");
}
if (!headers.Site) {
board.header("Site", "Freechess");
}
if (!headers.Date) {
board.header(
"Date",
new Date().toISOString().split("T")[0].replaceAll("-", ".")
);
}
return board;
};