Skip to content

Commit

Permalink
delete trainer route
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Morette committed May 22, 2024
1 parent 96d88e9 commit 6497971
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/controllers/TrainerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ class TrainerController {
});
}
};

static delete = (req, res) => {
models.trainer
.delete(req.params.idDiscord)
.then(() => {
res.sendStatus(204);
})
.catch((err) => {
console.error(err);
res.sendStatus(500);
});
};
}

module.exports = TrainerController;
7 changes: 7 additions & 0 deletions backend/src/models/TrainerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class TrainerManager extends AbstractManager {
[idDiscord]
);
}

delete(idDiscord) {
return this.connection.query(
`delete from ${TrainerManager.table} where idDiscord = ?`,
[idDiscord]
);
}
}

module.exports = TrainerManager;
1 change: 1 addition & 0 deletions backend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ router.get("/trainer/:idDiscord", TrainerController.read);
router.get("/trainer/verify/:idDiscord", TrainerController.verifyIdDiscord);
router.post("/trainer", TrainerController.add);
router.post("/trainer/pokemon/trade", TrainerController.tradePokemon);
router.delete("/trainer/:idDiscord", TrainerController.delete);

router.get("/rune/:idDiscordTrainer", RuneTrainerController.readByTrainer);
router.post("/rune/buy", RuneTrainerController.buy);
Expand Down

0 comments on commit 6497971

Please sign in to comment.