fix: change filtering survey
This commit is contained in:
parent
c653df0ce7
commit
6bcc466a76
@ -16,7 +16,7 @@ type SearchParams = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WhereCondition = {
|
type WhereCondition = {
|
||||||
AND?: any[]
|
AND: any[]
|
||||||
OR?: any[]
|
OR?: any[]
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ const ITEMS_PER_PAGE = 10
|
|||||||
* @returns 검색 조건 객체
|
* @returns 검색 조건 객체
|
||||||
*/
|
*/
|
||||||
const createKeywordSearchCondition = (keyword: string, searchOption: string): WhereCondition => {
|
const createKeywordSearchCondition = (keyword: string, searchOption: string): WhereCondition => {
|
||||||
const where: WhereCondition = {}
|
const where: WhereCondition = { AND: [] }
|
||||||
|
|
||||||
if (searchOption === 'all') {
|
if (searchOption === 'all') {
|
||||||
// 모든 필드 검색 시 OR 조건 사용
|
// 모든 필드 검색 시 OR 조건 사용
|
||||||
@ -74,7 +74,6 @@ const createKeywordSearchCondition = (keyword: string, searchOption: string): Wh
|
|||||||
where.ID = { equals: null }
|
where.ID = { equals: null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return where
|
return where
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,21 +104,18 @@ const createMemberRoleCondition = (params: SearchParams): WhereCondition => {
|
|||||||
AND: [
|
AND: [
|
||||||
{ STORE: { equals: params.store } },
|
{ STORE: { equals: params.store } },
|
||||||
{
|
{
|
||||||
OR: [
|
OR: [{ CONSTRUCTION_POINT: { equals: null } }, { CONSTRUCTION_POINT: { equals: '' } }],
|
||||||
{ CONSTRUCTION_POINT: { equals: null } },
|
},
|
||||||
{ CONSTRUCTION_POINT: { equals: '' } }
|
],
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
AND: [
|
AND: [
|
||||||
{ STORE: { equals: params.store } },
|
{ STORE: { equals: params.store } },
|
||||||
{ CONSTRUCTION_POINT: { not: null } },
|
{ CONSTRUCTION_POINT: { not: null } },
|
||||||
{ CONSTRUCTION_POINT: { not: '' } },
|
{ CONSTRUCTION_POINT: { not: '' } },
|
||||||
{ SUBMISSION_STATUS: { equals: true } }
|
{ SUBMISSION_STATUS: { equals: true } },
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -159,20 +155,23 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 검색 조건 구성
|
// 검색 조건 구성
|
||||||
const where: WhereCondition = {}
|
const where: WhereCondition = { AND: [] }
|
||||||
|
|
||||||
// 내가 작성한 매물 조건 적용
|
// 내가 작성한 매물 조건 적용
|
||||||
if (params.isMySurvey) {
|
if (params.isMySurvey) {
|
||||||
where.REPRESENTATIVE = params.isMySurvey
|
where.AND.push({ REPRESENTATIVE: params.isMySurvey })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 키워드 검색 조건 적용
|
// 키워드 검색 조건 적용
|
||||||
if (params.keyword && params.searchOption) {
|
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) {
|
if (params.offset) {
|
||||||
|
|||||||
@ -19,22 +19,26 @@ export default function ListTable() {
|
|||||||
const { session } = useSessionStore()
|
const { session } = useSessionStore()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (surveyList && surveyList.length > 0) {
|
if (surveyList) {
|
||||||
if (offset === 0) {
|
if (offset === 0) {
|
||||||
setHeldSurveyList(surveyList)
|
setHeldSurveyList(surveyList)
|
||||||
} else {
|
} else {
|
||||||
const remainingList = heldSurveyList.slice(offset, offset + 10)
|
setHeldSurveyList(prev => [...prev, ...surveyList])
|
||||||
if (JSON.stringify(remainingList) !== JSON.stringify(surveyList)) {
|
|
||||||
setHeldSurveyList((prev) => [...prev, ...surveyList])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setHasMore(surveyListCount > offset + 10)
|
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) => {
|
const handleDetailClick = (id: number) => {
|
||||||
router.push(`/survey-sale/${id}`)
|
router.push(`/survey-sale/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleItemsInit = () => {
|
const handleItemsInit = () => {
|
||||||
setHeldSurveyList([])
|
setHeldSurveyList([])
|
||||||
setOffset(0)
|
setOffset(0)
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem
|
|||||||
}
|
}
|
||||||
setKeyword(searchKeyword)
|
setKeyword(searchKeyword)
|
||||||
setSearchOption(option)
|
setSearchOption(option)
|
||||||
onItemsInit()
|
// onItemsInit()
|
||||||
}
|
}
|
||||||
const searchOptions = memberRole === 'Partner' ? SEARCH_OPTIONS_PARTNERS : SEARCH_OPTIONS
|
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') {
|
if (e.target.value === 'all') {
|
||||||
setKeyword('')
|
setKeyword('')
|
||||||
setSearchKeyword('')
|
setSearchKeyword('')
|
||||||
onItemsInit()
|
// onItemsInit()
|
||||||
setSearchOption('all')
|
setSearchOption('all')
|
||||||
setOption('all')
|
setOption('all')
|
||||||
} else {
|
} else {
|
||||||
@ -80,7 +80,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem
|
|||||||
checked={isMySurvey === userId}
|
checked={isMySurvey === userId}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
setIsMySurvey(isMySurvey === userId ? null : userId)
|
setIsMySurvey(isMySurvey === userId ? null : userId)
|
||||||
onItemsInit()
|
// onItemsInit()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="ch01">私が書いた物件</label>
|
<label htmlFor="ch01">私が書いた物件</label>
|
||||||
@ -94,7 +94,7 @@ export default function SearchForm({ onItemsInit, memberRole, userId }: { onItem
|
|||||||
value={sort}
|
value={sort}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setSort(e.target.value as 'created' | 'updated')
|
setSort(e.target.value as 'created' | 'updated')
|
||||||
onItemsInit()
|
// onItemsInit()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<option value="created">最近の登録日</option>
|
<option value="created">最近の登録日</option>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user