File tree Expand file tree Collapse file tree 2 files changed +29
-10
lines changed
Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -90,19 +90,32 @@ export interface NoticeUpsertRequest {
9090export const getNotices = async ( query ?: {
9191 offset ?: number ;
9292 limit ?: number ;
93- address ?: string ;
93+ address ?: string [ ] ;
9494 keyword ?: string ;
9595 startsAtGte ?: string ;
9696 hourlyPayGte ?: number ;
9797 sort ?: 'time' | 'pay' | 'hour' | 'shop' ;
9898} ) : Promise < GetNoticesResponse > => {
9999 try {
100- const newQuery = new URLSearchParams ( {
101- ...query ,
102- offset : String ( query ?. offset ?? '' ) ,
103- limit : String ( query ?. limit ?? '' ) ,
104- hourlyPayGte : String ( query ?. hourlyPayGte ?? '' ) ,
100+ const { address, ...rest } = query ?? { } ; // address만 분리
101+
102+ const newQuery = new URLSearchParams ( ) ;
103+
104+ // 키값을 하나씩 꺼내 문자열 변환
105+ Object . entries ( rest ) . forEach ( ( [ key , value ] ) => {
106+ if ( value !== undefined && value !== null ) {
107+ newQuery . set ( key , String ( value ) ) ;
108+ }
109+ } ) ;
110+
111+ // 배열로 각 값의 trim 적용, 유효한 값만 append
112+ address ?. forEach ( ( addr ) => {
113+ const trimmed = addr . trim ( ) ;
114+ if ( trimmed ) {
115+ newQuery . append ( 'address' , trimmed ) ;
116+ }
105117 } ) ;
118+
106119 const response = await api . get < GetNoticesResponse > ( `/notices?${ newQuery } ` ) ;
107120 return response . data ;
108121 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ export default function NoticeList({ search = '' }: { search?: string }) {
9090 const rawQuery = {
9191 offset : ( currentPage - 1 ) * ITEMS_PER_PAGE ,
9292 limit : ITEMS_PER_PAGE ,
93- address : filterValues . address ?. [ 0 ] ,
93+ address : filterValues . address ,
9494 keyword : search ,
9595 startsAtGte : filterValues . startsAt ?? getTomorrowISOString ( ) ,
9696 hourlyPayGte : filterValues . hourlyPay ,
@@ -134,13 +134,19 @@ export default function NoticeList({ search = '' }: { search?: string }) {
134134 const userInfo = await getUser ( userId ) ;
135135 const preferredAddress = userInfo . item . address ;
136136
137+ let addressArray : string [ ] = [ ] ;
138+ if ( preferredAddress ) {
139+ addressArray = Array . isArray ( preferredAddress )
140+ ? preferredAddress
141+ : [ preferredAddress ] ;
142+ }
143+
137144 const result = await getNotices ( {
138145 offset : 0 ,
139146 limit : 9 ,
140147 startsAtGte : getTomorrowISOString ( ) ,
141- ...( preferredAddress
142- ? { address : preferredAddress }
143- : { sort : 'shop' } ) ,
148+ address : addressArray . length > 0 ? addressArray : undefined ,
149+ sort : addressArray . length === 0 ? 'shop' : undefined ,
144150 } ) ;
145151
146152 setRecommendedNotices (
You can’t perform that action at this time.
0 commit comments