diff --git a/src/app/api/survey-sales/route.ts b/src/app/api/survey-sales/route.ts index d4b676a..23f3d18 100644 --- a/src/app/api/survey-sales/route.ts +++ b/src/app/api/survey-sales/route.ts @@ -16,7 +16,7 @@ type SearchParams = { } type WhereCondition = { - AND?: any[] + AND: any[] OR?: any[] [key: string]: any } @@ -43,7 +43,7 @@ const ITEMS_PER_PAGE = 10 * @returns 검색 조건 객체 */ const createKeywordSearchCondition = (keyword: string, searchOption: string): WhereCondition => { - const where: WhereCondition = {} + const where: WhereCondition = { AND: [] } if (searchOption === 'all') { // 모든 필드 검색 시 OR 조건 사용 @@ -74,7 +74,6 @@ const createKeywordSearchCondition = (keyword: string, searchOption: string): Wh where.ID = { equals: null } } } - return where } @@ -105,21 +104,18 @@ const createMemberRoleCondition = (params: SearchParams): WhereCondition => { AND: [ { STORE: { equals: params.store } }, { - OR: [ - { CONSTRUCTION_POINT: { equals: null } }, - { CONSTRUCTION_POINT: { equals: '' } } - ] - } - ] + OR: [{ CONSTRUCTION_POINT: { equals: null } }, { CONSTRUCTION_POINT: { equals: '' } }], + }, + ], }, { AND: [ { STORE: { equals: params.store } }, { CONSTRUCTION_POINT: { not: null } }, { CONSTRUCTION_POINT: { not: '' } }, - { SUBMISSION_STATUS: { equals: true } } - ] - } + { SUBMISSION_STATUS: { equals: true } }, + ], + }, ] break @@ -159,20 +155,23 @@ export async function GET(request: Request) { } // 검색 조건 구성 - const where: WhereCondition = {} + const where: WhereCondition = { AND: [] } // 내가 작성한 매물 조건 적용 if (params.isMySurvey) { - where.REPRESENTATIVE = params.isMySurvey + where.AND.push({ REPRESENTATIVE: params.isMySurvey }) } // 키워드 검색 조건 적용 if (params.keyword && params.searchOption) { - Object.assign(where, createKeywordSearchCondition(params.keyword, params.searchOption)) + where.AND.push(createKeywordSearchCondition(params.keyword, params.searchOption)) } // 회원 유형 조건 적용 - Object.assign(where, createMemberRoleCondition(params)) + const roleCondition = createMemberRoleCondition(params) + if (Object.keys(roleCondition).length > 0) { + where.AND.push(roleCondition) + } // 데이터 조회 또는 카운트 if (params.offset) { diff --git a/src/components/survey-sale/list/ListTable.tsx b/src/components/survey-sale/list/ListTable.tsx index 16351b7..468f01d 100644 --- a/src/components/survey-sale/list/ListTable.tsx +++ b/src/components/survey-sale/list/ListTable.tsx @@ -19,22 +19,26 @@ export default function ListTable() { const { session } = useSessionStore() useEffect(() => { - if (surveyList && surveyList.length > 0) { + if (surveyList) { if (offset === 0) { setHeldSurveyList(surveyList) } else { - const remainingList = heldSurveyList.slice(offset, offset + 10) - if (JSON.stringify(remainingList) !== JSON.stringify(surveyList)) { - setHeldSurveyList((prev) => [...prev, ...surveyList]) - } + setHeldSurveyList(prev => [...prev, ...surveyList]) } setHasMore(surveyListCount > offset + 10) + } else { + setHeldSurveyList([]) + setHasMore(false) } - }, [surveyList, surveyListCount, offset, session?.role]) + }, [surveyList, surveyListCount, offset]) + + console.log('surveyList:: ', surveyList) + console.log('heldSurveyList:: ', heldSurveyList) const handleDetailClick = (id: number) => { router.push(`/survey-sale/${id}`) } + const handleItemsInit = () => { setHeldSurveyList([]) setOffset(0) diff --git a/src/components/survey-sale/list/SearchForm.tsx b/src/components/survey-sale/list/SearchForm.tsx index 3f3d234..16a259d 100644 --- a/src/components/survey-sale/list/SearchForm.tsx +++ b/src/components/survey-sale/list/SearchForm.tsx @@ -17,7 +17,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem } setKeyword(searchKeyword) setSearchOption(option) - onItemsInit() + // onItemsInit() } const searchOptions = memberRole === 'Partner' ? SEARCH_OPTIONS_PARTNERS : SEARCH_OPTIONS @@ -38,7 +38,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem if (e.target.value === 'all') { setKeyword('') setSearchKeyword('') - onItemsInit() + // onItemsInit() setSearchOption('all') setOption('all') } else { @@ -80,7 +80,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem checked={isMySurvey === userId} onChange={() => { setIsMySurvey(isMySurvey === userId ? null : userId) - onItemsInit() + // onItemsInit() }} /> @@ -94,7 +94,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem value={sort} onChange={(e) => { setSort(e.target.value as 'created' | 'updated') - onItemsInit() + // onItemsInit() }} >