Publish and edit routes are working

This commit is contained in:
2021-01-30 07:40:04 +11:00
parent 689a3371f1
commit 9b8ef8f2e7
10 changed files with 107 additions and 21 deletions
+34
View File
@@ -0,0 +1,34 @@
const { articles } = require('../database/models');
const route = async (req, res) => {
//check the key
if (req.body.key != process.env.QUERY_KEY) {
return res.status(401).json({ ok: false, error: 'invalid key' });
}
//upsert the data
const [instance, created] = await articles.upsert({
title: req.body.title,
author: req.body.author,
body: req.body.body
});
if (!created) {
return res.status(500).json({ ok: false, error: 'failed to create record' });
}
//BUGFIX
const result = await articles.findOne({
order: [
['index', 'DESC']
]
});
return res.status(200).json({
ok: true,
// index: instance.get('index')
index: result.index
});
};
module.exports = route;