v1.12.22 관리자 멤버 댓글 목록 및 최근 댓글 확인 추가

This commit is contained in:
2026-10-21 15:34:31 +09:00
parent 6886c57d04
commit c8e00c1190
15 changed files with 255 additions and 9 deletions

View File

@@ -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 } }
})
}

View File

@@ -0,0 +1,24 @@
import { createError, getQuery } from 'h3'
import { z } from 'zod'
import { requireAdminSession } from '../../../utils/admin-auth'
import { listAdminComments } from '../../../repositories/comment-repository'
const querySchema = z.object({
memberId: z.string().uuid().optional(),
page: z.coerce.number().int().min(1).max(1000000).default(1),
pageSize: z.coerce.number().int().min(1).max(100).default(10)
})
/**
* 관리자 전용 댓글 목록을 조회한다.
* @param {import('h3').H3Event} event - 요청 이벤트
* @returns {Promise<Object>} 댓글 페이지
*/
export default defineEventHandler((event) => {
requireAdminSession(event)
const result = querySchema.safeParse(getQuery(event))
if (!result.success) {
throw createError({ statusCode: 400, message: '댓글 조회 조건이 올바르지 않습니다.' })
}
return listAdminComments(result.data)
})