Add league configuration endpoint and frontend integration for myTischtennis
Implemented a new POST endpoint in MyTischtennisUrlController to configure leagues from table URLs, including season creation logic. Updated myTischtennisRoutes to include the new route for league configuration. Enhanced the myTischtennisUrlParserService to support parsing of table URLs and added a method for decoding group names. Updated TeamManagementView.vue to prompt users for league configuration when a table URL is detected, providing feedback upon successful configuration and reloading relevant data.
This commit is contained in:
@@ -402,6 +402,89 @@ class MyTischtennisUrlController {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure league from myTischtennis table URL
|
||||
* POST /api/mytischtennis/configure-league
|
||||
* Body: { url: string, createSeason?: boolean }
|
||||
*/
|
||||
async configureLeague(req, res, next) {
|
||||
try {
|
||||
const { url, createSeason } = req.body;
|
||||
const userIdOrEmail = req.headers.userid;
|
||||
|
||||
if (!url) {
|
||||
throw new HttpError(400, 'URL is required');
|
||||
}
|
||||
|
||||
// Parse URL
|
||||
const parsedData = myTischtennisUrlParserService.parseUrl(url);
|
||||
|
||||
if (parsedData.urlType !== 'table') {
|
||||
throw new HttpError(400, 'URL must be a table URL (not a team URL)');
|
||||
}
|
||||
|
||||
// Find or create season
|
||||
let season = await Season.findOne({
|
||||
where: { season: parsedData.season }
|
||||
});
|
||||
|
||||
if (!season && createSeason) {
|
||||
season = await Season.create({
|
||||
season: parsedData.season,
|
||||
startDate: new Date(),
|
||||
endDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) // 1 Jahr später
|
||||
});
|
||||
}
|
||||
|
||||
// Find or create league
|
||||
let league = await League.findOne({
|
||||
where: {
|
||||
myTischtennisGroupId: parsedData.groupId,
|
||||
association: parsedData.association
|
||||
}
|
||||
});
|
||||
|
||||
if (!league) {
|
||||
league = await League.create({
|
||||
name: parsedData.groupnameOriginal, // Verwende die originale URL-kodierte Version
|
||||
myTischtennisGroupId: parsedData.groupId,
|
||||
association: parsedData.association,
|
||||
groupname: parsedData.groupnameOriginal, // Verwende die originale URL-kodierte Version
|
||||
seasonId: season?.id || null
|
||||
});
|
||||
} else {
|
||||
// Update existing league - aber nur wenn es sich wirklich geändert hat
|
||||
if (league.name !== parsedData.groupnameOriginal) {
|
||||
league.name = parsedData.groupnameOriginal;
|
||||
league.groupname = parsedData.groupnameOriginal;
|
||||
}
|
||||
league.seasonId = season?.id || league.seasonId;
|
||||
await league.save();
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'League configured successfully',
|
||||
data: {
|
||||
league: {
|
||||
id: league.id,
|
||||
name: league.name,
|
||||
myTischtennisGroupId: league.myTischtennisGroupId,
|
||||
association: league.association,
|
||||
groupname: league.groupname
|
||||
},
|
||||
season: season ? {
|
||||
id: season.id,
|
||||
name: season.season
|
||||
} : null,
|
||||
parsedData
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new MyTischtennisUrlController();
|
||||
|
||||
Reference in New Issue
Block a user