v1.12.22 관리자 멤버 댓글 목록 및 최근 댓글 확인 추가
This commit is contained in:
@@ -329,3 +329,38 @@ export const toggleCommentLike = async (input) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 댓글을 작성자 조건과 최신순 페이지 단위로 조회한다.
|
||||
* @param {{ memberId?: string, page: number, pageSize: number }} options - 조회 조건
|
||||
* @returns {Promise<Object>} 댓글과 페이지 정보
|
||||
*/
|
||||
export const listAdminComments = async ({ memberId = null, page, pageSize }) => {
|
||||
const sql = getSql()
|
||||
const empty = { items: [], pagination: { page: 1, pageSize, total: 0, pageCount: 1 } }
|
||||
if (!sql) return empty
|
||||
|
||||
return sql.begin(async (transaction) => {
|
||||
await transaction`SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY`
|
||||
const [count] = await transaction`
|
||||
SELECT COUNT(*)::int AS total FROM comments
|
||||
WHERE (${memberId}::uuid IS NULL OR user_id = ${memberId}::uuid)
|
||||
`
|
||||
const total = Number(count.total)
|
||||
const pageCount = Math.max(1, Math.ceil(total / pageSize))
|
||||
const currentPage = Math.min(page, pageCount)
|
||||
const items = await transaction`
|
||||
SELECT comments.id, comments.body, comments.status,
|
||||
comments.parent_id AS "parentId", comments.created_at AS "createdAt",
|
||||
users.id AS "userId", users.username,
|
||||
posts.id AS "postId", posts.title AS "postTitle", posts.slug AS "postSlug",
|
||||
posts.status AS "postStatus"
|
||||
FROM comments
|
||||
INNER JOIN users ON users.id = comments.user_id
|
||||
INNER JOIN posts ON posts.id = comments.post_id
|
||||
WHERE (${memberId}::uuid IS NULL OR comments.user_id = ${memberId}::uuid)
|
||||
ORDER BY comments.created_at DESC, comments.id DESC
|
||||
LIMIT ${pageSize} OFFSET ${(currentPage - 1) * pageSize}
|
||||
`
|
||||
return { items, pagination: { page: currentPage, pageSize, total, pageCount } }
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user