코드 무한 스크롤 구현
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user