// controller.js
// insert into database
Article.create()
// find all (no need to re-write static fn within the model
Article.findAll()
// find by Id, primary key
Article.findByPk()
const article = await Article.findOne({ where: { id } });
const article = await Article.findOne({ where: { id: uuid } });
// find all & custom
const article = await Article.findAll({ where: { id: uuid } });
// update
// get existing article
const existingArticle = await Article.findByPk(articleId);
// if article exists
if (existingArticle) {
existingArticle.title = title;
existingArticle.content = content;
existingArticle.featuredImage = featuredImage;
// do not change slug, or status or id
// save updated article (with Sequelize instance method)
await existingArticle.save();
console.log('Article saved: ', existingArticle.title);
res.redirect('/list');
}
// delete
// find article by id
articleToDelete = await Article.findByPk(articleId);
if (articleToDelete) {
articleToDelete.destroy();
console.log('Article deleted: ', articleToDelete.title);
res.redirect('/list');
}