列出最近posts
This commit is contained in:
父節點
1bcaa0f84b
當前提交
1ebd5aa4aa
@ -29,4 +29,5 @@ export class PostModel {
|
||||
async setStatusByPostId(id: number, status: TPostStatus) {
|
||||
console.log(await db.query('update posts set status=? where id=?', [status, id]))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import 'reflect-metadata'
|
||||
import {Container} from "typedi"
|
||||
import {PostService} from "../services/post-service"
|
||||
import express from "express"
|
||||
import {body} from "express-validator"
|
||||
import {body, query} from "express-validator"
|
||||
import * as Validator from "validator"
|
||||
import {hasValidationErrors} from "../includes"
|
||||
import {JWTUserPayload} from "../types"
|
||||
@ -16,7 +16,14 @@ postRouter.post('/submit',
|
||||
body('image').isURL({host_whitelist: [/.*\.360buyimg\.com/]}).withMessage('仅支援*.360buyimg.com下的图片'),
|
||||
async (req: express.Request, res: express.Response) => {
|
||||
if (hasValidationErrors(req, res)) return
|
||||
res.json(await postService.submit(req.user as JWTUserPayload,req.body.content, req.body.image))
|
||||
res.json(await postService.submit(req.user as JWTUserPayload, req.body.content, req.body.image))
|
||||
}
|
||||
)
|
||||
postRouter.get('/listPublished',
|
||||
query('page').default(1).isInt({min: 1}).withMessage('页码必须>=1'),
|
||||
async (req: express.Request, res: express.Response) => {
|
||||
if (hasValidationErrors(req, res)) return
|
||||
res.json(await postService.listPublished(req.query.page as any as number))
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -19,4 +19,9 @@ export class PostService {
|
||||
})
|
||||
return resultJson.success(packet.insertId)
|
||||
}
|
||||
|
||||
async listPublished(page: number) {
|
||||
let posts = await this.postModel.findPostsByStatus(2, page)
|
||||
return resultJson.success(posts)
|
||||
}
|
||||
}
|
||||
|
載入中…
x
新增問題並參考
Block a user