-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor and image for tournaments (#256)
* feat: refactor and image for tournaments * fix: test
- Loading branch information
Showing
20 changed files
with
380 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export type Tournament = { | ||
id: number; | ||
created_at: string; | ||
default_match_length: number | null; | ||
name: string; | ||
max_participants: number; | ||
team_capacity: number; | ||
rules: string | null; | ||
prize: string | null; | ||
id_address: number | null; | ||
id_sport: number | null; | ||
description: string | null; | ||
}; | ||
|
||
export type Sport = { | ||
id: number; | ||
name: string; | ||
}; | ||
|
||
export type Address = { | ||
id: number; | ||
road: string; | ||
number: number; | ||
complement: string | null; | ||
name: string | null; | ||
}; | ||
|
||
export type Round = { | ||
id: number; | ||
name: string; | ||
id_tournament: number; | ||
order: number; | ||
}; | ||
|
||
export type Team = { | ||
id: number; | ||
name: string; | ||
validate: boolean; | ||
users: { | ||
id: number; | ||
username: string; | ||
}[]; | ||
}; | ||
|
||
export type Match = { | ||
id: number; | ||
start_time: string | null; | ||
end_time: string | null; | ||
id_round: number; | ||
winner: number[]; | ||
teams: Team[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use server'; | ||
|
||
import type { Tournament } from '@/app/lib/type/Tournaments'; | ||
import { cookies } from 'next/headers'; | ||
|
||
const urlApi = process.env.ATHLONIX_API_URL; | ||
|
||
export async function getTournament( | ||
page: number, | ||
searchTerm: string, | ||
): Promise<{ data: { data: Tournament[]; count: number }; status: number }> { | ||
const queryParams = new URLSearchParams({ | ||
skip: `${page - 1}`, | ||
take: '10', | ||
search: searchTerm, | ||
}); | ||
|
||
const res = await fetch(`${urlApi}/tournaments?${queryParams}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${cookies().get('access_token')?.value}`, | ||
}, | ||
}); | ||
|
||
return { data: await res.json(), status: res.status }; | ||
} | ||
|
||
export async function createTournament(formData: FormData): Promise<{ data: Tournament; status: number }> { | ||
const res = await fetch(`${urlApi}/tournaments`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${cookies().get('access_token')?.value}`, | ||
}, | ||
body: formData, | ||
}); | ||
|
||
return { data: await res.json(), status: res.status }; | ||
} |
Oops, something went wrong.