-1
I’m trying to create a Postings in Node. A post can be created, shown or deleted. For this I created a table called posts with the following fields :
table.string('category').notNullable()
table.string('title').notNullable()
table.string('description').notNullable()
This given my system will have 3 possible operations for this Posting entity : Create, Index (show) and Delete. To carry out the deletion of a post I wish to inform the title of one already present in the BD and then this be excluded. Here is the implementation of the operation of Destroy in my Controller :
async delete (request, response){
const{title} = request.params
const postagem = await connection('posts')
.where('title', title)//significa procurar um título que seja igual ao const{title} = request.params definido acima
.select('title')//selecionando apenas a coluna title da tabela
.first()//como terá apenas um resultado, o first deletará o primeiro resultado do título que vier
if(postagem.title != title){//se o título da postagem que colocamos for diferente da do título dentro do bd ...
return response.status(401).json({error : 'Operation not permitted'})//não autorizado, ou seja, erro
}
await connection('posts').where('title', tile).delete()
}
Once done, I make a request like DELETE in JSON format as follows :
{
"title": "<titulo da Postagem a ser excluida>"
}
And I get the following error message :
(Node:7699) Unhandledpromiserejectionwarning: Error: Undefined Binding(s) Detected when compiling FIRST. Undefined column(s): [title] query: select title_id
from posts
Where title
= ? limit ?
How can I delete a Post by sending the title field in JSON format as demonstrated?
Undefined column(s): [title]
– Augusto Vasques