2022-10-30 02:03:54 +00:00
|
|
|
import type { GameType, SavedGameType } from '$lib/types';
|
2023-10-14 09:06:57 +00:00
|
|
|
import kebabCase from 'just-kebab-case';
|
2024-02-23 03:13:04 +00:00
|
|
|
import type { Games } from '../../schema';
|
2022-10-30 02:03:54 +00:00
|
|
|
|
2022-11-03 05:16:52 +00:00
|
|
|
export function convertToSavedGame(game: GameType | SavedGameType): SavedGameType {
|
2022-12-29 06:21:55 +00:00
|
|
|
return {
|
|
|
|
|
id: game.id,
|
|
|
|
|
name: game.name,
|
|
|
|
|
thumb_url: game.thumb_url,
|
|
|
|
|
players: game.players,
|
|
|
|
|
playtime: game.playtime,
|
|
|
|
|
searchTerms: `${game.name.toLowerCase()}`
|
|
|
|
|
};
|
2022-11-03 05:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-30 02:03:54 +00:00
|
|
|
export function mapSavedGameToGame(game: SavedGameType): GameType {
|
2022-12-29 06:21:55 +00:00
|
|
|
const { id, name, thumb_url, players, playtime } = game;
|
|
|
|
|
console.log({ id, name, thumb_url, players, playtime });
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
handle: '',
|
|
|
|
|
name,
|
|
|
|
|
url: '',
|
|
|
|
|
edit_url: '',
|
|
|
|
|
thumb_url,
|
|
|
|
|
image_url: '',
|
|
|
|
|
price: 0,
|
|
|
|
|
price_ca: 0,
|
|
|
|
|
price_uk: 0,
|
|
|
|
|
price_au: 0,
|
|
|
|
|
msrp: 0,
|
|
|
|
|
year_published: new Date().getFullYear(),
|
|
|
|
|
min_players: 0,
|
|
|
|
|
max_players: 0,
|
|
|
|
|
min_playtime: 0,
|
|
|
|
|
max_playtime: 0,
|
|
|
|
|
min_age: 0,
|
|
|
|
|
description: '',
|
|
|
|
|
description_preview: '',
|
|
|
|
|
players,
|
|
|
|
|
playtime
|
|
|
|
|
};
|
2022-10-30 02:03:54 +00:00
|
|
|
}
|
2022-07-27 22:05:22 +00:00
|
|
|
|
2024-02-23 03:13:04 +00:00
|
|
|
export function mapAPIGameToBoredGame(game: GameType): Games {
|
2023-10-14 09:06:57 +00:00
|
|
|
// TODO: Fix types
|
2022-12-29 06:21:55 +00:00
|
|
|
return {
|
2023-10-14 09:06:57 +00:00
|
|
|
name: game.name,
|
|
|
|
|
slug: kebabCase(game.name),
|
|
|
|
|
thumb_url: game.thumbnail,
|
|
|
|
|
image_url: game.image,
|
|
|
|
|
year_published: game.year_published,
|
|
|
|
|
min_players: game.min_players,
|
|
|
|
|
max_players: game.max_players,
|
|
|
|
|
min_playtime: game.min_playtime,
|
|
|
|
|
max_playtime: game.max_playtime,
|
|
|
|
|
min_age: game.min_age,
|
2024-02-23 03:13:04 +00:00
|
|
|
description: game.description
|
2022-12-29 06:21:55 +00:00
|
|
|
};
|
2022-07-28 00:05:54 +00:00
|
|
|
}
|