choudhmh
New Coder
Good day
Writing this code there one of the database field is vote - within the javascript i have this parameter called increment votes. When any number is passed through the parameter the votes for that id within the table must be increased by the the parameter amount (or decrease). Got everything working but not sure how to add the inc_vote paramter into my sql. If anyone can help me with that part of the sql statement will appreciate it. Currently studying java script:
how can i add the part in bold so it gets accepted by the sql statement
and for the testing this is how i am testing to see the outcome:
Thanks
Writing this code there one of the database field is vote - within the javascript i have this parameter called increment votes. When any number is passed through the parameter the votes for that id within the table must be increased by the the parameter amount (or decrease). Got everything working but not sure how to add the inc_vote paramter into my sql. If anyone can help me with that part of the sql statement will appreciate it. Currently studying java script:
Code:
const incVoteById = (article_id, inc_votes) => {
if (inc_votes === undefined) throw ({status: 400, msg: 'invalid input syntax for type'})
else
return db.query('UPDATE article SET votes = ${inc_votes} WHERE article_id= $1 RETURNING *;',[article_id])
.then(([article]) => {
if (article === undefined) {
throw ({ status: 404, msg: 'article not found' })
}
else return article;
})
}
how can i add the part in bold so it gets accepted by the sql statement
and for the testing this is how i am testing to see the outcome:
Code:
it.only('PATCH 200 - responds with an object containing the updated article (article 1))', () => {
return request(app)
.patch('/api/articles/1')
.send({ inc_votes: 100 })
.expect(200)
.then(({body}) => {
expect(body.article).toEqual(
expect.objectContaining({
article_id: expect.any(Number),
title: expect.any(String),
body: expect.any(String),
votes: expect.any(Number),
topic: expect.any(String),
author: expect.any(String),
created_at: expect.any(String)
})
)
expect(body.article.votes).toBe(200)
})
})
Thanks