Ajout: load match
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
1c30bdffb5
commit
5b2b142646
@ -1,18 +1,25 @@
|
||||
import React from "react";
|
||||
import create from "zustand";
|
||||
import { Match } from "../core/Match/match";
|
||||
import { User } from "../core/User/user";
|
||||
|
||||
|
||||
// Define store types
|
||||
interface MatchState {
|
||||
match: Match | null;
|
||||
tabUser: User[] | null[];
|
||||
setMatch: (match: Match|null) => void;
|
||||
resetMatch: () => void;
|
||||
setTabUser: (tabUser: User[] | null[]) => void;
|
||||
resetTabUser: () => void;
|
||||
}
|
||||
|
||||
// Define store data and methods
|
||||
export const useMatchStore = create<MatchState>()((set, get) => ({
|
||||
match: null,
|
||||
tabUser: [],
|
||||
setMatch: (match) => set((state) => ({ match: match })),
|
||||
resetMatch: () => set((state) => ({ match: null })),
|
||||
setTabUser: (tabUser) => set((state) => ({ tabUser: tabUser })),
|
||||
resetTabUser: () => set((state) => ({ tabUser: [] })),
|
||||
}));
|
||||
|
@ -1,13 +1,66 @@
|
||||
import { rejects } from "assert";
|
||||
import { MANAGER_GAME, MANAGER_USER } from "../../../appManagers";
|
||||
import { GameCasino } from "../../core/gameCasino";
|
||||
import { GameMulti } from "../../core/gameMulti";
|
||||
import { Match } from "../../core/Match/match";
|
||||
import MatchCasino from "../../core/Match/matchCasino";
|
||||
import MatchMulti from "../../core/Match/matchMulti";
|
||||
import { User } from "../../core/User/user";
|
||||
import ILoaderMatch from "./ILoaderMatch";
|
||||
|
||||
export default class LoaderMatchApi implements ILoaderMatch{
|
||||
|
||||
private axios = require('axios').default;
|
||||
|
||||
|
||||
async loadAllMatch(): Promise<Match[]> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
async loadByID(id: string): Promise<Match | null> {
|
||||
throw new Error("Method not implemented.");
|
||||
|
||||
async loadByID(id: number): Promise<Match | null> {
|
||||
let match:Match|null=null;
|
||||
const url='http://localhost:8888/api-rest/index.php/getMatchById/' + id;
|
||||
await this.axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
})
|
||||
.then(async function (response: any) {
|
||||
if (response.data != null || response.data != undefined){
|
||||
match=await jsonToMatch(response);
|
||||
}
|
||||
});
|
||||
return match;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function jsonToMatch(response: any){
|
||||
let match: Match| null=null;
|
||||
const tabUs: User[]=[];
|
||||
let users=new Promise<void>((resolve, reject) => {
|
||||
response.data.listIdUsers.forEach(async (idUser: number) => {
|
||||
await MANAGER_USER.getLoaderUser().loadByID(idUser).then((res) =>{
|
||||
if (res!==null){
|
||||
tabUs.push(res);
|
||||
}
|
||||
});
|
||||
if (tabUs.length===response.data.listIdUsers.length){
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
const game = await MANAGER_GAME.getLoaderGame().loadByID(response.data.idGame);
|
||||
await Promise.all([users]);
|
||||
if (game!==null){
|
||||
if (game instanceof GameMulti){
|
||||
match = new MatchMulti(response.data.id, response.data.inGame, tabUs, game);
|
||||
}
|
||||
else if (game instanceof GameCasino){
|
||||
match = new MatchCasino(response.data.id, response.data.inGame, tabUs, game)
|
||||
}
|
||||
}
|
||||
return match;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue