mirror of
https://github.com/FranP-code/open-react-blog-api.git
synced 2025-10-12 23:52:57 +00:00
Sorting blogpost by last modificated time added for /user endpoint
This commit is contained in:
@@ -49,13 +49,12 @@ router.post("/", async (req, res) => {
|
||||
userData.posts = []
|
||||
|
||||
try {
|
||||
|
||||
const postsReference = await db.collection('users').doc(userData.id).collection("posts").get()
|
||||
|
||||
postsReference.forEach(doc => {
|
||||
userData.posts.push({
|
||||
id: doc.id,
|
||||
data: doc.data()
|
||||
...doc.data()
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
@@ -63,6 +62,9 @@ router.post("/", async (req, res) => {
|
||||
res.status(400).json(err)
|
||||
}
|
||||
|
||||
//Order posts by last modificated time
|
||||
userData.posts.sort((a, b) => b.date.seconds-a.date.seconds)
|
||||
|
||||
//Hide user id
|
||||
userData.id = null
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ require('dotenv').config();
|
||||
const express = require("express");
|
||||
const server = express()
|
||||
|
||||
const port = process.env.PORT || 3000
|
||||
const port = process.env.PORT || 3001
|
||||
|
||||
//Accept with JSON files
|
||||
server.use(express.json())
|
||||
|
||||
Reference in New Issue
Block a user