코드 무한 스크롤 구현

This commit is contained in:
2025-09-03 18:23:23 +09:00
parent ce4a25a10b
commit 55f6925b06
11 changed files with 237 additions and 97 deletions

View File

@@ -40,6 +40,8 @@ export interface GetCategoriesParams {
export interface GetCodesParams {
search?: string;
isActive?: boolean;
page?: number;
size?: number;
}
export interface CreateCategoryData {
@@ -112,7 +114,7 @@ export class CommonCodeService {
*/
async getCodes(categoryCode: string, params: GetCodesParams) {
try {
const { search, isActive } = params;
const { search, isActive, page = 1, size = 20 } = params;
let whereClause: any = {
code_category: categoryCode,
@@ -129,14 +131,23 @@ export class CommonCodeService {
whereClause.is_active = isActive ? "Y" : "N";
}
const codes = await prisma.code_info.findMany({
where: whereClause,
orderBy: [{ sort_order: "asc" }, { code_value: "asc" }],
});
const offset = (page - 1) * size;
logger.info(`코드 조회 완료: ${categoryCode} - ${codes.length}`);
const [codes, total] = await Promise.all([
prisma.code_info.findMany({
where: whereClause,
orderBy: [{ sort_order: "asc" }, { code_value: "asc" }],
skip: offset,
take: size,
}),
prisma.code_info.count({ where: whereClause }),
]);
return codes;
logger.info(
`코드 조회 완료: ${categoryCode} - ${codes.length}개, 전체: ${total}`
);
return { data: codes, total };
} catch (error) {
logger.error(`코드 조회 중 오류 (${categoryCode}):`, error);
throw error;