feature(database-connection): Parse dates in response

This commit is contained in:
2021-01-12 15:57:48 +01:00
parent e3951d4793
commit bbdbd04cc8

View File

@@ -1,10 +1,10 @@
import RequestError from "../models/RequestError"; import RequestError from "../models/RequestError";
import UserStatsResponse from "../models/UserStatsResponse"; import UserStatsResponse from "../models/UserStatsResponse";
import {useEffect, useState} from "react";
export default class UserStatsService { export default class UserStatsService {
private static apiURL = 'https://api.tsotr.humenius.me/stats' // private static apiURL = 'https://api.tsotr.humenius.me/stats'
private static apiURL = 'http://localhost:3500/stats'
private static requestInit: RequestInit = { private static requestInit: RequestInit = {
method: 'GET', method: 'GET',
@@ -14,9 +14,14 @@ export default class UserStatsService {
}; };
public static async getStats(seasonId: string): Promise<UserStatsResponse> { public static async getStats(seasonId: string): Promise<UserStatsResponse> {
return fetch(this.apiURL, this.requestInit) return fetch(`${this.apiURL}/season/${seasonId}`, this.requestInit)
.then(res => UserStatsService.checkResponse(res)) .then(res => UserStatsService.checkResponse(res))
.then(data => data.json()); .then(data => data.json())
.then(data => {
data.dates.start = new Date(data.dates.start)
data.dates.end = new Date(data.dates.end)
return data
})
} }
private static checkResponse(response: any): any { private static checkResponse(response: any): any {