some tweaking here and there
This commit is contained in:
+12
-1
@@ -3,7 +3,7 @@ const router = require('express').Router();
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
try{
|
||||
const username = req.user;
|
||||
const username = 'kajvans';
|
||||
const {title, content, category} = req.body;
|
||||
|
||||
if(title.length > process.env.MAXTITLELENGTH) return res.status(400).json({error: "Title is too long"});
|
||||
@@ -23,6 +23,7 @@ router.post('/', async (req, res) => {
|
||||
postId = (newPost[0].id).slice(6);
|
||||
|
||||
const update = await db.query(`UPDATE users SET posts += "${postId}" WHERE username = string::lowercase("${username}")`)
|
||||
const update2 = await db.query(`UPDATE category SET posts += "${postId}" WHERE name = string::lowercase("${category}")`)
|
||||
|
||||
res.status(200).json({message: "Post created"});
|
||||
}
|
||||
@@ -46,6 +47,7 @@ router.delete('/:id', async (req, res) => {
|
||||
|
||||
const deletePost = await db.query(`DELETE FROM posts WHERE id = "${id}"`);
|
||||
const update = await db.query(`UPDATE users SET posts -= "${id}" WHERE username = string::lowercase("${username}")`)
|
||||
const update2 = await db.query(`UPDATE category SET posts -= "${id}" WHERE name = string::lowercase("${post.category}")`)
|
||||
|
||||
res.status(200).json({message: "Post deleted"});
|
||||
}
|
||||
@@ -55,4 +57,13 @@ router.delete('/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/category', async (req, res) => {
|
||||
const category = req.body.category;
|
||||
const description = req.body.description;
|
||||
if(!category) return res.status(400).json({error: "Missing category"});
|
||||
|
||||
const newCategory = await db.create('category', {name: category, description: description, posts: []});
|
||||
res.status(200).json({message: "Category created"});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user