-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes and add ability to delete goals
- Loading branch information
1 parent
ce44b0c
commit e1d462c
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { getCustomError } = require("../../../helpers/errorHandler"); | ||
const { getAuthenticatedUser } = require("../../../helpers/authenticationHelpers"); | ||
|
||
async function deleteGoal(req, res, db) { | ||
if ( | ||
!req.params || | ||
!req.params.goal_id | ||
) { | ||
return res.status(400).json(getCustomError(400)); | ||
} | ||
|
||
const authenticatedUser = getAuthenticatedUser(req.headers); | ||
|
||
if (!authenticatedUser) { | ||
return res.status(401).json(getCustomError(401)); | ||
} | ||
|
||
await db('goals').where({ | ||
user_email: authenticatedUser.email, | ||
id: req.params.goal_id | ||
}).del(); | ||
|
||
return res.json({ | ||
type: "Goal deleted", | ||
attributes: { | ||
value: req.params.goal_id | ||
} | ||
}); | ||
} | ||
|
||
module.exports = deleteGoal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters