21 行
742 B
TypeScript
21 行
742 B
TypeScript
import 'reflect-metadata'
|
|
import {Service} from "typedi"
|
|
import {IPost, TPostStatus} from "../types"
|
|
import {db, pageToLimitSqlSegment} from "../includes"
|
|
import {fillIPost} from "../helpers/entity-fill"
|
|
|
|
@Service()
|
|
export class PostModel {
|
|
async insertPost(post: IPost) {
|
|
return db.query('insert into posts (userId,content,image,status,time) values(?,?,?,?,?)', [
|
|
post.userId, post.content, post.image, post.status, post.time
|
|
])
|
|
}
|
|
|
|
async findPostByStatus(status: TPostStatus, page: number) {
|
|
let arr = await db.query('select * from posts where status=? order by time desc '
|
|
+ pageToLimitSqlSegment(page),[status])
|
|
return arr.map((single: any) => fillIPost(single))
|
|
}
|
|
}
|