Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exercise.delete("/cant-do-exercises", verifyJwt, async (req, res) => {
- const {exerciseId, userId} = req.body;
- const currentUserId = req.userId;
- if (!exerciseId || !userId) {
- res.statusCode = 422;
- return res.json({
- data: null,
- error: {message: "Required query parameter [exerciseId|userId] is missing."}
- });
- }
- if (currentUserId !== userId) {
- try {
- if (!await trainerHasClient(currentUserId, userId)) {
- return res.json({
- data: null,
- error: {message: "No authorization to do this."}
- });
- }
- } catch (error) {
- return res.json({
- data: null,
- error: {message: error.message}
- });
- }
- }
- try {
- await knexDb("cant_do_exercises")
- .where("exerciseId", exerciseId)
- .andWhere("userId", userId)
- .delete();
- return res.json({
- data: {exerciseId},
- error: null
- });
- } catch (error) {
- return res.json({
- data: null,
- error: {message: error.message}
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement