v1.12.23 대시보드 간소화 및 멤버 작성 이력 탭 추가
This commit is contained in:
@@ -2906,3 +2906,34 @@ export const deleteAdminTag = async (id) => {
|
||||
|
||||
return Boolean(rows[0])
|
||||
}
|
||||
|
||||
/**
|
||||
* 회원이 작성한 전체 게시물을 최신 작성순으로 검색·페이지 조회한다.
|
||||
* @param {{ memberId: string, q: string, page: number, pageSize: number }} options - 조회 조건
|
||||
* @returns {Promise<Object>} 게시물 요약과 페이지 정보
|
||||
*/
|
||||
export const listAdminMemberPosts = async ({ memberId, q, page, pageSize }) => {
|
||||
const sql = getPostgresClient()
|
||||
if (!sql) return { items: [], pagination: { page: 1, pageSize, total: 0, pageCount: 1 } }
|
||||
|
||||
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 posts
|
||||
WHERE author_id = ${memberId}
|
||||
AND (${q} = '' OR strpos(lower(concat_ws(' ', title, slug, excerpt, content)), lower(${q})) > 0)
|
||||
`
|
||||
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 id, title, slug, status, created_at AS "createdAt", published_at AS "publishedAt"
|
||||
FROM posts
|
||||
WHERE author_id = ${memberId}
|
||||
AND (${q} = '' OR strpos(lower(concat_ws(' ', title, slug, excerpt, content)), lower(${q})) > 0)
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT ${pageSize} OFFSET ${(currentPage - 1) * pageSize}
|
||||
`
|
||||
return { items, pagination: { page: currentPage, pageSize, total, pageCount } }
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user