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 = []
|
userData.posts = []
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const postsReference = await db.collection('users').doc(userData.id).collection("posts").get()
|
const postsReference = await db.collection('users').doc(userData.id).collection("posts").get()
|
||||||
|
|
||||||
postsReference.forEach(doc => {
|
postsReference.forEach(doc => {
|
||||||
userData.posts.push({
|
userData.posts.push({
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
data: doc.data()
|
...doc.data()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -63,6 +62,9 @@ router.post("/", async (req, res) => {
|
|||||||
res.status(400).json(err)
|
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
|
//Hide user id
|
||||||
userData.id = null
|
userData.id = null
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ require('dotenv').config();
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const server = express()
|
const server = express()
|
||||||
|
|
||||||
const port = process.env.PORT || 3000
|
const port = process.env.PORT || 3001
|
||||||
|
|
||||||
//Accept with JSON files
|
//Accept with JSON files
|
||||||
server.use(express.json())
|
server.use(express.json())
|
||||||
|
|||||||
Reference in New Issue
Block a user