Skip to content
Snippets Groups Projects
Commit 25123cff authored by elit04's avatar elit04
Browse files

check if color is defined in create sport controller

parent ffeeb9aa
No related branches found
No related tags found
No related merge requests found
......@@ -26,15 +26,17 @@ const createSportController = async (req: Request, res: Response) => {
}
//check if color already assigned to another sport (for the statistics)
const findIfColorAlreadyAssigned = await Sport.findOne({
where: {
color: newSportInput.color,
},
});
if (findIfColorAlreadyAssigned) {
return res
.status(404)
.json({ success: false, error: "givenSportColorAlreadyExists" });
if (!(newSportInput.color === undefined)) {
const findIfColorAlreadyAssigned = await Sport.findOne({
where: {
color: newSportInput.color,
},
});
if (findIfColorAlreadyAssigned) {
return res
.status(404)
.json({ success: false, error: "givenSportColorAlreadyExists" });
}
}
const newSport = await Sport.create(newSportInput);
......@@ -249,12 +251,10 @@ const showSportBySportId = async (req: Request, res: Response) => {
const givenId = req.params.id;
const sport = await Sport.findByPk(givenId);
if (sport) {
return res
.status(200)
.json({
success: true,
result: { id: givenId, name: sport.name, color: sport.color },
});
return res.status(200).json({
success: true,
result: { id: givenId, name: sport.name, color: sport.color },
});
}
return res.status(404).json({ success: false, error: "sportIdNotFound" });
} catch (error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment