I am trying to add records to a postgres db that have a sequelize datatype of an array of strings. I am using thunderclient and trying to do the POST request with the array of strings that I want to be in the record, and I keep getting 404 error.
Here is my schema
module.exports = (sequelize, DataTypes) => {
return sequelize.define('character', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
nicknames: {
type: DataTypes.ARRAY(DataTypes.STRING),
default: [],
allowNull: true,
},
});
};
Here is my route:
router.post('/api/characters', async (req, res, next) => {
const character = req.body;
try {
let response = await CharacterModel.create(character);
console.log('response: ', response);
res.status(200).send(response);
} catch (e) {
res.status(404).send('Cannot perform this method');
}
});
And here is how I have the body of the request written:
{
"name": "name",
"nicknames": ["nickname1", "nickname2"]
}
I have tried removing the nicknames part from the schema and do just the name, which is just the simple DataTypes.STRING and I get a status 200 on that post request just fine, so I know its something to do with the syntax of the array in the nicknames field. Anybody know how to get the array of strings to work? I have not been able to find any specific examples of the json body syntax itself.