import { Injectable } from '@angular/core'; import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs"; import { API_URL } from "../../app.constants"; import { AppState } from "../../types/app-state"; import { Participant } from "../../types/participant"; import { Question } from "../../types/question"; import { CardItem } from "../../types/card-item"; import { GameState } from "./gameState"; import { PenaltyDto } from "../../types/penalty.dto"; import { PrizeDto } from "../../types/prize.dto"; import {QuestionresultsDto} from "../../types/questionresults.dto"; import {map} from "rxjs/operators"; import {VersusItem} from "../../types/versus-item"; export interface FeatureFlagStateDto { name: string; state: boolean; } export interface StateInformationDto { key: string; value: { key: string; value: T }; } export interface StateInformationVersusDto { action: any; player1: number; player2: number; } export interface ConfigRecordDto { key: string; value: string; } @Injectable({ providedIn: 'root' }) export class ApiService { constructor(private httpClient: HttpClient) { } public getAppState(state: string): Observable { return this.httpClient.get(`${API_URL}/state/${state}`); } public getParticipants(): Observable { return this.httpClient.get(`${API_URL}/guests`); } public getParticipant(id: number): Observable { return this.httpClient.get(`${API_URL}/guests/${id}`); } public getQuestion(): Observable { return this.httpClient.get(`${API_URL}/quiz`); } public setAppState(state: string, value: string) { return this.httpClient.post(`${API_URL}/state`, { state, value }); } getCards(telegramId: number): Observable { return this.httpClient.get(`${API_URL}/cards/${telegramId}`); } continueGame() { console.log(`continue game`); return this.httpClient.post(`${API_URL}/quiz/proceed`, {}); } markQueueAsCompleted(_id: string) { return this.httpClient.post(`${API_URL}/game/${_id}/complete`, {}); } pauseGame() { return this.httpClient.post(`${API_URL}/game/pause`, {}); } resumeGame() { return this.httpClient.post(`${API_URL}/game/resume`, {}); } getGameState() { return this.httpClient.get(`${API_URL}/game/state`); } getPenalty() { console.log(`get penalty`); return this.httpClient.get(`${API_URL}/penalty`); } playExtraCards() { console.log(`play extra cards`); return this.httpClient.get(`${API_URL}/game/playextracards`); } getAdditionalQuestion(target: number) { return this.httpClient.post(`${API_URL}/quiz/extraquestion`, { telegramId: target, }); } getImageUrl(id: number) { const timestamp = new Date().getTime(); return `${API_URL}/guests/photo/${id}?$t=${timestamp}}`; } getPrize(): Observable { return this.httpClient.get(`${API_URL}/gifts`); } getQuestionResults() { return this.httpClient.get(`${API_URL}/quiz/question-results`) } getFeatureFlagState(feature: string) { return this.httpClient.get(`${API_URL}/featureflag/${feature}`); } setFeatureFlagState(feature: string, state: boolean) { return this.httpClient.post(`${API_URL}/featureflag`, { name: feature, state: state }); } getStateDetails() { return this.httpClient.get(`${API_URL}/game/state-details`); } getVersus() { return this.httpClient.get(`${API_URL}/versus`); } completeVersus(winner: number) { return this.httpClient.post(`${API_URL}/versus/complete`, { winner: winner }); } }