Skip to content

Commit

Permalink
Merge pull request #52 from fac19/readme
Browse files Browse the repository at this point in the history
Fix getExample handling 204
  • Loading branch information
Alexreid95 authored Apr 18, 2020
2 parents c2eb1be + 5d0fbc9 commit bd60bbd
Show file tree
Hide file tree
Showing 4 changed files with 2,331 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package-lock.json


node_modules

Expand Down
43 changes: 22 additions & 21 deletions handlers/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,49 @@ function post(req, res, next) {

function del(req, res, next) {
modelExample
.deleteExample( req.params.id, req.user )
.deleteExample(req.params.id, req.user)
.then(() => {
res.status(200).send({deleted: true})
res.status(200).send({ deleted: true });
})
.catch(next);

}

function getExample(req, res, next) {
const id = req.params.id;
modelExample
.getExample(id)
.then((result) => {
console.log(!result === undefined);
if (!result) {
res.status(204).send("Error: Resource not found");
}
res.status(200).send(result);
})
.catch(next);
}

function updateExample(req, res, next) {
const id = Number(req.params.id);
const userID = req.user.id;
const newdata = req.body;
if (id === NaN) {
const err = new Error ('This is not a valid ID')
err.status = 401;
next(err)
}

modelExample
.updateExamplebyID(id, newdata, userID)
.then(result => {
res.status(200).send(result)
})
.catch(next);

const id = Number(req.params.id);
const userID = req.user.id;
const newdata = req.body;
if (id === NaN) {
const err = new Error("This is not a valid ID");
err.status = 401;
next(err);
}

modelExample
.updateExamplebyID(id, newdata, userID)
.then((result) => {
res.status(200).send(result);
})
.catch(next);
}

module.exports = {
getAllExamples,
post,
getExample,
del,
updateExample
del,
updateExample,
};
Loading

0 comments on commit bd60bbd

Please sign in to comment.