HOTFIX: Missing data would crash the site
This commit is contained in:
Generated
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "news-server",
|
"name": "news-server",
|
||||||
"version": "1.1.1",
|
"version": "1.2.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"version": "1.1.1",
|
"version": "1.2.2",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "news-server",
|
"name": "news-server",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"description": "An API centric news server. Uses Sequelize and mariaDB by default.",
|
"description": "An API centric news server. Uses Sequelize and mariaDB by default.",
|
||||||
"main": "server/server.js",
|
"main": "server/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+3
-3
@@ -25,9 +25,9 @@ const route = async (req, res) => {
|
|||||||
|
|
||||||
//update the data
|
//update the data
|
||||||
await articles.update({
|
await articles.update({
|
||||||
title: req.body.title,
|
title: req.body.title || record.title,
|
||||||
author: req.body.author,
|
author: req.body.author || record.author,
|
||||||
body: req.body.body,
|
body: req.body.body || record.body,
|
||||||
edits: record.edits + 1
|
edits: record.edits + 1
|
||||||
}, {
|
}, {
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
const { articles } = require('../database/models');
|
const { articles } = require('../database/models');
|
||||||
|
|
||||||
const route = async (req, res) => {
|
const route = async (req, res) => {
|
||||||
|
//check for missing data
|
||||||
|
if (!req.body.title) {
|
||||||
|
return res.status(401).end("Missing title");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.body.author) {
|
||||||
|
return res.status(401).end("Missing author");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.body.body) {
|
||||||
|
return res.status(401).end("Missing body");
|
||||||
|
}
|
||||||
|
|
||||||
//upsert the data
|
//upsert the data
|
||||||
const [instance, created] = await articles.upsert({
|
const [instance, created] = await articles.upsert({
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
|
|||||||
Reference in New Issue
Block a user