fix: change filtering survey

This commit is contained in:
Dayoung 2025-05-16 14:58:15 +09:00
parent c653df0ce7
commit 6bcc466a76
3 changed files with 29 additions and 26 deletions

View File

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

View File

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

View File

@ -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()
}}
/>
<label htmlFor="ch01"></label>
@ -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()
}}
>
<option value="created"></option>