tuned some things and added some to user route
This commit is contained in:
+3
-2
@@ -4,7 +4,7 @@ const router = require('express').Router();
|
||||
router.post('/', async (req, res) => {
|
||||
try{
|
||||
const username = req.user;
|
||||
const {title, content} = req.body;
|
||||
const {title, content, category} = req.body;
|
||||
|
||||
if(title.length > process.env.MAXTITLELENGTH) return res.status(400).json({error: "Title is too long"});
|
||||
if(content.length > process.env.MAXCONTENTLENGTH) return res.status(400).json({error: "Content is too long"});
|
||||
@@ -12,13 +12,14 @@ router.post('/', async (req, res) => {
|
||||
if(title.length < process.env.MINTITLELENGTH) return res.status(400).json({error: "Title is too short"});
|
||||
if(content.length < process.env.MINCONTENTLENGTH) return res.status(400).json({error: "Content is too short"});
|
||||
if(!username) return res.status(400).json({error: "Missing username"});
|
||||
if(!category) return res.status(400).json({error: "Missing category"});
|
||||
|
||||
const currentDate = new Date();
|
||||
const formattedDateAndTime = currentDate.toLocaleTimeString('en-gb', { timeStyle: 'short' });
|
||||
const formattedDate = currentDate.toLocaleDateString('en-gb');
|
||||
const date = formattedDateAndTime + " " + formattedDate;
|
||||
|
||||
const newPost = await db.create('posts', {title: title, content: content, author: username, date: date});
|
||||
const newPost = await db.create('posts', {category: category, title: title, content: content, author: username, date: date});
|
||||
postId = (newPost[0].id).slice(6);
|
||||
|
||||
const update = await db.query(`UPDATE users SET posts += "${postId}" WHERE username = string::lowercase("${username}")`)
|
||||
|
||||
Reference in New Issue
Block a user