-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronisation des tournois #175
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Joueur } from '@/types/interfaces/joueur'; | ||
import { supabase } from '@/utils/supabase'; | ||
|
||
export const synchroniserJoueurs = async ( | ||
joueurs: Joueur[], | ||
tournoi_id: number, | ||
): Promise<void> => { | ||
joueurs.forEach(async (joueur) => { | ||
const updatedJoueur = { | ||
tournoi_id: tournoi_id, | ||
joueur_id: joueur.id, | ||
nom: joueur.name, | ||
type: joueur.type, | ||
equipe: joueur.equipe, | ||
coche: joueur.isChecked, | ||
//created_at: tournoi.creationDate, | ||
//updated_at: tournoi.updateDate, | ||
}; | ||
upsertJoueurs(updatedJoueur); | ||
}); | ||
}; | ||
|
||
export const upsertJoueurs = async (updatedJoueur): Promise<void> => { | ||
const { | ||
data: { user }, | ||
} = await supabase.auth.getUser(); | ||
if (!user) { | ||
throw new Error('No user on the session!'); | ||
} | ||
|
||
updatedJoueur.user_id = user.id; | ||
const { data, error } = await supabase | ||
.from('joueurs') | ||
.upsert(updatedJoueur, { onConflict: 'tournoi_id, joueur_id' }) | ||
.select(); | ||
console.log('upsertJoueurs'); | ||
console.log(data); | ||
console.log(error); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||
import { Match } from '@/types/interfaces/match'; | ||||||||||||||||||||||||||
import { supabase } from '@/utils/supabase'; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const synchroniserMatchs = async ( | ||||||||||||||||||||||||||
matchs: Match[], | ||||||||||||||||||||||||||
tournoi_id: number, | ||||||||||||||||||||||||||
): Promise<void> => { | ||||||||||||||||||||||||||
matchs.forEach(async (match) => { | ||||||||||||||||||||||||||
const updatedMatch = { | ||||||||||||||||||||||||||
tournoi_id: tournoi_id, | ||||||||||||||||||||||||||
match_id: match.id, | ||||||||||||||||||||||||||
score_1: match.score1, | ||||||||||||||||||||||||||
score_2: match.score2, | ||||||||||||||||||||||||||
manche: match.manche, | ||||||||||||||||||||||||||
manche_nom: match.mancheName, | ||||||||||||||||||||||||||
//created_at: tournoi.creationDate, | ||||||||||||||||||||||||||
//updated_at: tournoi.updateDate, | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
upsertMatchs(updatedMatch); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const upsertMatchs = async (updatedMatch): Promise<void> => { | ||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||
data: { user }, | ||||||||||||||||||||||||||
} = await supabase.auth.getUser(); | ||||||||||||||||||||||||||
if (!user) { | ||||||||||||||||||||||||||
throw new Error('No user on the session!'); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
updatedMatch.user_id = user.id; | ||||||||||||||||||||||||||
const { data, error } = await supabase | ||||||||||||||||||||||||||
Check warning Code scanning / ESLint Disallow unused variables Warning
'error' is assigned a value but never used.
Copilot Autofix AI 3 months ago To fix the problem, we need to handle the We will modify the
Suggested changeset
1
src/services/matchsServices.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
||||||||||||||||||||||||||
.from('matchs') | ||||||||||||||||||||||||||
.upsert(updatedMatch, { onConflict: 'tournoi_id, match_id' }) | ||||||||||||||||||||||||||
.select(); | ||||||||||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||||||||||
import { Tournoi } from '@/types/interfaces/tournoi'; | ||||||||||||||||||||||||||||||||||||||
import { supabase } from '@/utils/supabase'; | ||||||||||||||||||||||||||||||||||||||
import { Match } from '@/types/interfaces/match'; | ||||||||||||||||||||||||||||||||||||||
import { OptionsTournoi } from '@/types/interfaces/optionsTournoi'; | ||||||||||||||||||||||||||||||||||||||
import { synchroniserJoueurs } from './joueursServices'; | ||||||||||||||||||||||||||||||||||||||
import { synchroniserMatchs } from './matchsServices'; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export const synchroniserTournois = async ( | ||||||||||||||||||||||||||||||||||||||
tournois: Tournoi[], | ||||||||||||||||||||||||||||||||||||||
): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||
tournois.forEach(async (tournoi) => { | ||||||||||||||||||||||||||||||||||||||
const updatedTournoi = { | ||||||||||||||||||||||||||||||||||||||
tournoi_id: tournoi.tournoiId, | ||||||||||||||||||||||||||||||||||||||
nom: tournoi.name, | ||||||||||||||||||||||||||||||||||||||
created_at: tournoi.creationDate, | ||||||||||||||||||||||||||||||||||||||
updated_at: tournoi.updateDate, | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
upsertTournois(updatedTournoi); | ||||||||||||||||||||||||||||||||||||||
let matchs = tournoi.tournoi.slice(0, -1) as Match[]; | ||||||||||||||||||||||||||||||||||||||
let optionsTournoi = tournoi.tournoi.at(-1) as OptionsTournoi; | ||||||||||||||||||||||||||||||||||||||
const tournoiServ = await getTournoi(tournoi.tournoiId); | ||||||||||||||||||||||||||||||||||||||
synchroniserMatchs(matchs, tournoiServ.id); | ||||||||||||||||||||||||||||||||||||||
synchroniserJoueurs(optionsTournoi.listeJoueurs, tournoiServ.id); | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export const upsertTournois = async (updatedTournoi): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||
data: { user }, | ||||||||||||||||||||||||||||||||||||||
} = await supabase.auth.getUser(); | ||||||||||||||||||||||||||||||||||||||
if (!user) { | ||||||||||||||||||||||||||||||||||||||
throw new Error('No user on the session!'); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
updatedTournoi.user_id = user.id; | ||||||||||||||||||||||||||||||||||||||
const { data, error } = await supabase | ||||||||||||||||||||||||||||||||||||||
Check warning Code scanning / ESLint Disallow unused variables Warning
'data' is assigned a value but never used.
Copilot Autofix AI 3 months ago To fix the problem, we should remove the unused variable
Suggested changeset
1
src/services/tournoisService.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
Check warning Code scanning / ESLint Disallow unused variables Warning
'error' is assigned a value but never used.
Copilot Autofix AI 3 months ago To fix the problem, we need to handle the We will modify the
Suggested changeset
1
src/services/tournoisService.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||
.from('tournois') | ||||||||||||||||||||||||||||||||||||||
.upsert(updatedTournoi, { onConflict: 'user_id, tournoi_id' }) | ||||||||||||||||||||||||||||||||||||||
.select(); | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export const getTournoi = async (tournoiId: number): Promise<any> => { | ||||||||||||||||||||||||||||||||||||||
const { data, error } = await supabase | ||||||||||||||||||||||||||||||||||||||
Check warning Code scanning / ESLint Disallow unused variables Warning
'error' is assigned a value but never used.
Copilot Autofix AI 3 months ago To fix the problem, we need to remove the unused
Suggested changeset
1
src/services/tournoisService.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||
.from('tournois') | ||||||||||||||||||||||||||||||||||||||
.select() | ||||||||||||||||||||||||||||||||||||||
.eq('tournoi_id', tournoiId); | ||||||||||||||||||||||||||||||||||||||
return data[0]; | ||||||||||||||||||||||||||||||||||||||
}; |
Check warning
Code scanning / ESLint
Disallow unused variables Warning
Copilot Autofix AI 3 months ago
The best way to fix the problem is to remove the unused variable
data
. This will clean up the code and adhere to the ESLint rule. Sincedata
is not used anywhere in the function, we can safely remove its declaration without affecting the existing functionality.To implement this fix, we need to:
data
variable from the destructuring assignment on line 32.