63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { BaseService } from './base-service'
|
|
import { Game } from '@/interfaces/game'
|
|
import { ValidateMetadataDto } from '@/dtos/validate-metadata.dto'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
import { AuthDto } from '@/dtos/auth.dto'
|
|
|
|
export class GameService extends BaseService {
|
|
|
|
public getGames(): Promise<Game[]> {
|
|
return this.get<Game[]>("games")
|
|
}
|
|
|
|
public getGame(gameId: string): Promise<Game> {
|
|
return this.get<Game>(`games/${gameId}`)
|
|
}
|
|
|
|
public async upload(game: FormData) : Promise<Response> {
|
|
const authStr = useAuthStore();
|
|
return this.postForm(`games`, game, {
|
|
Authorization: `Bearer ${authStr.getAuth()?.token}`,
|
|
});
|
|
}
|
|
|
|
public async update(game: Game) : Promise<void> {
|
|
await this.put<any>(`games`, null)
|
|
}
|
|
|
|
public async activate(gameId: string): Promise<void> {
|
|
await this.post<any>(`games/${gameId}/activate`, null)
|
|
}
|
|
|
|
public async deactivate(gameId: string): Promise<void> {
|
|
await this.post<any>(`games/${gameId}/deactivate`, null)
|
|
}
|
|
|
|
public async download(gameId: string): Promise<void> {
|
|
await this.get<any>(`games/${gameId}/download`)
|
|
}
|
|
|
|
public async downloadAll(): Promise<void> {
|
|
await this.get<any>(`games/download`)
|
|
}
|
|
|
|
public async patch(): Promise<void> {
|
|
await this.put<any>(`games/patch`, null)
|
|
}
|
|
|
|
public async minor(): Promise<void> {
|
|
await this.put<any>(`games/minor`, null)
|
|
}
|
|
|
|
public async major(): Promise<void> {
|
|
await this.put<any>(`games/major`, null)
|
|
}
|
|
|
|
public async metadata(dto: ValidateMetadataDto): Promise<Response> {
|
|
return this.post(`games/metadata`, dto)
|
|
}
|
|
|
|
public async deleteGame(gameId: string): Promise<void> {
|
|
await this.delete(`games/${gameId}`)
|
|
}
|
|
} |