Skip to content

Commit

Permalink
fix the code according to TL comments
Browse files Browse the repository at this point in the history
Relates #26
  • Loading branch information
alaa-yasin committed Sep 24, 2019
1 parent 11d72e6 commit 3961b65
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions server/controllers/postFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const feedbackSchema = require('../validation/feedback');
module.exports = (req, res, next) => {
feedbackSchema
.validateAsync(req.body)
.then((data) => postFeedback(data))
.then(postFeedback)
.then(() => {
res.status(200).send({ statusCode: 200, message: 'Your feedback has sent!' });
res.status(201).send({ statusCode: 201, message: 'Your feedback has sent!' });
})
.catch((err) => {
if (err.details) {
if (err.details[0].message) {
res.status(400).send({ statusCode: 400, message: err.details[0].message });
res.status(400).send({ statusCode: 400, error: err.details[0].message });
}
} else {
next(err);
Expand Down
2 changes: 1 addition & 1 deletion server/database/queries/postFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const connection = require('../config/connection');
module.exports = (data) => {
const { orderId, email, feedback } = data;
const sql = {
text: 'INSERT INTO feedback (order_id, email, feedback) values ($1, $2, $3);',
text: 'INSERT INTO feedback (order_id, email, feedback) VALUES ($1, $2, $3);',
values: [orderId, email, feedback],
};
return connection.query(sql);
Expand Down
4 changes: 2 additions & 2 deletions test/feedback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ tape('testing post feedback route', (t) => {
.post('/api/v1/post-feedback')
.send({ orderId: 2, email: '[email protected]', feedback: 'Every thing is good' })
.expect('Content-Type', /json/)
.expect(200)
.expect(201)
.end((err, res) => {
if (err) {
t.error(err);
t.end();
} else {
t.deepEqual(res.body, { statusCode: 200, message: 'Your feedback has sent!' }, 'should be the same');
t.deepEqual(res.body, { statusCode: 201, message: 'Your feedback has sent!' }, 'should be the same');
t.end();
}
});
Expand Down

0 comments on commit 3961b65

Please sign in to comment.