When creating a data with Fetch by javascript, they come as Null when displayed on the screen, but by Postman it is done as normal. You can help? The ID is also shown normally in the html, but author and txt are not
export const listPhrases = async (req: Request, res: Response) => {
let list = await Phrase.findAll({})
res.json({list})
}
export const createPhrase = async (req: Request, res: Response) => {
let { author, txt} = req.body;
let newPhrase = await Phrase.create({ author, txt });
res.status(201);
res.json({ id: newPhrase.id, author, txt });
}
async function getPhrases () {
const response = await fetch('http://localhost:4000/frases')
const data = await response.json()
const phrase = await (data.list)
let newPhrases = '';
phrase.forEach(((item) => {
let newPhrasesPost = `
<h5>${item.txt}</h5>`
newPhrases += newPhrasesPost
}))
document.getElementById("phrase").innerHTML = newPhrases;
}
async function newPhrase() {
let inputPhrase = document.getElementById("inputPhrase").value;
let author = document.getElementById("author").value;
let phrasePost = { inputPhrase, author };
const options = {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(phrasePost)
};
const response = await fetch("http://localhost:4000/frases", options);
getPhrases();
}