feat: improve type definitions and refactor API responses for better type safety
Some checks failed
CI / lint (push) Failing after 7s
CI / test-backend (push) Has been skipped
CI / test-frontend (push) Has been skipped
CI / test-e2e (push) Has been skipped

This commit is contained in:
2026-03-18 19:37:23 +01:00
parent a07096d7c7
commit 3096a9b472
15 changed files with 528 additions and 161 deletions

View File

@@ -1,5 +1,59 @@
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000/api';
// Tipos para relaciones del juego
export interface Artwork {
id: string;
type: string;
sourceUrl: string;
localPath?: string;
width?: number;
height?: number;
fetchedAt: string;
}
export interface Purchase {
id: string;
priceCents: number;
currency: string;
store?: string;
date: string;
receiptPath?: string;
}
export interface GamePlatform {
id: string;
platform: {
id: string;
name: string;
slug: string;
generation?: number;
};
}
export interface Tag {
id: string;
name: string;
}
// Tipos para metadatos de búsqueda
export interface MetadataGame {
id?: number;
name: string;
slug?: string;
releaseDate?: string;
genres?: string[];
platforms?: PlatformInfo[];
coverUrl?: string;
source?: string;
}
export interface PlatformInfo {
id?: number;
name?: string;
abbreviation?: string;
slug?: string;
}
export interface Game {
id: string;
title: string;
@@ -31,10 +85,10 @@ export interface Game {
createdAt: string;
updatedAt: string;
// Relaciones
artworks?: any[];
purchases?: any[];
gamePlatforms?: any[];
tags?: any[];
artworks?: Artwork[];
purchases?: Purchase[];
gamePlatforms?: GamePlatform[];
tags?: Tag[];
}
export interface CreateGameInput {
@@ -161,7 +215,7 @@ export const importApi = {
};
export const metadataApi = {
searchIGDB: async (query: string): Promise<any[]> => {
searchIGDB: async (query: string): Promise<MetadataGame[]> => {
const response = await fetch(`${API_BASE}/metadata/igdb/search?q=${encodeURIComponent(query)}`);
if (!response.ok) {
throw new Error(`Error searching IGDB: ${response.statusText}`);
@@ -169,7 +223,7 @@ export const metadataApi = {
return response.json();
},
searchRAWG: async (query: string): Promise<any[]> => {
searchRAWG: async (query: string): Promise<MetadataGame[]> => {
const response = await fetch(`${API_BASE}/metadata/rawg/search?q=${encodeURIComponent(query)}`);
if (!response.ok) {
throw new Error(`Error searching RAWG: ${response.statusText}`);
@@ -177,7 +231,7 @@ export const metadataApi = {
return response.json();
},
searchTheGamesDB: async (query: string): Promise<any[]> => {
searchTheGamesDB: async (query: string): Promise<MetadataGame[]> => {
const response = await fetch(
`${API_BASE}/metadata/thegamesdb/search?q=${encodeURIComponent(query)}`
);