import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class ApiService { server_route = 'http://localhost:3000' constructor(private http: HttpClient) { } getMessage() { return this.http.get( 'http://localhost:3000/api/message'); } postReplayUpload(file: any) { const headers = new HttpHeaders(); headers.append('Content-Type', 'multipart/form-data'); return this.http.post( this.server_route+'/api/upload-replay', file, { headers }); } postReplayUploadV2(file: FormData, seasonId: string) { const headers = new HttpHeaders(); headers.append('Content-Type', 'multipart/form-data'); return this.http.post( this.server_route+'/api/upload-replay', { file, seasonId }, { headers }); } getSeasons() { return this.http.get( this.server_route+'/api/seasons'); } getSeasonDetails(id: string) { return this.http.get( this.server_route+'/api/seasons/'+id); } addSeason(title: string, subTitle: string, startDate: Date) { return this.http.post<{title: string, subtitle: string, startDate: Date}>(this.server_route+'/api/seasons/add', { title, subTitle, startDate }, {headers: { authorization: `Bearer ${localStorage.getItem('token')}` },}); } addRace(seasonId: string, startDate: Date, endDate: Date, mapUID: string, weekNumber: Number) { return this.http.post<{title: string, subtitle: string, startDate: Date}>(this.server_route+'/api/race/add', { seasonId, startDate, endDate, mapUID, weekNumber }, {headers: { authorization: `Bearer ${localStorage.getItem('token')}` },}); } }