tweaking and adding homepage with trending and so on
This commit is contained in:
+45
-1
@@ -23,7 +23,8 @@ router.get('/:username',publicauth, async (req, res) => {
|
||||
likedPosts: user[0].likedPosts,
|
||||
comments: user[0].comments,
|
||||
savedPosts: user[0].savedPosts,
|
||||
visibility: user[0].visibility
|
||||
visibility: user[0].visibility,
|
||||
activity: user[0].activity
|
||||
}
|
||||
|
||||
res.status(200).json({returnData});
|
||||
@@ -209,4 +210,47 @@ router.get('/visibility', auth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/activity/:type', auth, async (req, res) => {
|
||||
try{
|
||||
const type = req.params.type;
|
||||
const username = req.user;
|
||||
|
||||
if(!type) return res.status(400).json({error: "Missing type"});
|
||||
if(!username) return res.status(400).json({error: "Missing username"});
|
||||
|
||||
const user = await db.query(`SELECT activity FROM users WHERE username = string::lowercase("${username}")`);
|
||||
|
||||
if(user.length == 0) return res.status(400).json({error: "User does not exist"});
|
||||
|
||||
const activity = user[0].activity;
|
||||
|
||||
if(activity.length > 100){
|
||||
//remove oldest activity until length is 100
|
||||
while(activity.length > 100 - 1){
|
||||
activity.shift();
|
||||
}
|
||||
}
|
||||
|
||||
const currentDate = new Date();
|
||||
const formattedDateAndTime = currentDate.toLocaleTimeString('en-gb', { timeStyle: 'short' });
|
||||
const formattedDate = currentDate.toLocaleDateString('en-gb');
|
||||
const date = formattedDateAndTime + " " + formattedDate;
|
||||
|
||||
const newActivity = {
|
||||
type: type,
|
||||
date: date
|
||||
}
|
||||
|
||||
activity.push(newActivity);
|
||||
|
||||
const newActivityDB = await db.query(`UPDATE users SET activity = "${activity}" WHERE username = string::lowercase("${username}")`);
|
||||
|
||||
res.status(200).json({message: "Activity updated"});
|
||||
}
|
||||
catch(err){
|
||||
console.log(err);
|
||||
res.status(500).json({error: "Internal server error"});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user