Declarando tipos e serviço mock de jogos
This commit is contained in:
parent
49b6e6b071
commit
a1fe3aad81
2 changed files with 46 additions and 0 deletions
37
src/serviço/jogos.ts
Normal file
37
src/serviço/jogos.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Jogo } from "@/types";
|
||||
import { randomUUID, UUID } from "crypto";
|
||||
|
||||
const jogos: Jogo[] = [
|
||||
{
|
||||
id: "35f008ee-6828-40dc-b58e-136b9441db19",
|
||||
nome: "Jogo ai",
|
||||
estado: "NOVO",
|
||||
},
|
||||
{
|
||||
id: "f9302f75-b23b-4889-97d8-4e54afd28668",
|
||||
nome: "Outro jogo",
|
||||
estado: "JOGUEI",
|
||||
},
|
||||
];
|
||||
|
||||
export async function buscaJogos(): Promise<Jogo[]> {
|
||||
return [...jogos];
|
||||
}
|
||||
|
||||
export async function criaJogo(jogo: Jogo) {
|
||||
jogo.id = randomUUID();
|
||||
jogos.push(jogo);
|
||||
}
|
||||
|
||||
export async function atualizaJogo(idJogo: UUID, jogo: Jogo) {
|
||||
const index = jogos.findIndex((j) => j.id === idJogo);
|
||||
if (index === -1) return;
|
||||
jogos[index] = jogo;
|
||||
}
|
||||
|
||||
export async function removeJogo(idJogo?: UUID, jogo?: Jogo) {
|
||||
idJogo = idJogo || jogo?.id;
|
||||
const index = jogos.findIndex((j) => j.id === idJogo);
|
||||
if (index === -1) return;
|
||||
jogos.splice(index, 1);
|
||||
}
|
9
src/types.ts
Normal file
9
src/types.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { UUID } from "crypto";
|
||||
|
||||
export type Jogo = {
|
||||
id: UUID,
|
||||
nome: string,
|
||||
estado: Estado
|
||||
};
|
||||
|
||||
export type Estado = 'NOVO' | 'JOGUEI' | 'SATISFEITO';
|
Loading…
Reference in a new issue