Converted api/announcements to use api/announcement processer as its part

This commit is contained in:
Dmitriy Shishkov 2023-07-18 23:07:41 +03:00
parent de8a1abcbf
commit bc55ab8f68
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
2 changed files with 16 additions and 12 deletions

View File

@ -0,0 +1,12 @@
import { Announcement, AnnouncementResponse } from './types'
const processAnnouncement = (data: AnnouncementResponse): Announcement => ({
...data,
lat: data.latitude,
lng: data.longtitude,
bestBy: data.best_by,
bookedBy: data.booked_by,
userId: data.user_id
})
export { processAnnouncement }

View File

@ -1,5 +1,6 @@
import { API_URL } from '../../config' import { API_URL } from '../../config'
import { FiltersType, URLEncodeFilters } from '../../utils/filters' import { FiltersType, URLEncodeFilters } from '../../utils/filters'
import { processAnnouncement } from '../announcement'
import { Announcement } from '../announcement/types' import { Announcement } from '../announcement/types'
import { AnnouncementsResponse } from './types' import { AnnouncementsResponse } from './types'
@ -9,17 +10,8 @@ const composeAnnouncementsURL = (filters: FiltersType) => (
API_URL + '/announcements?' + new URLSearchParams(URLEncodeFilters(filters)).toString() API_URL + '/announcements?' + new URLSearchParams(URLEncodeFilters(filters)).toString()
) )
const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => { const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => (
const annList = data.list_of_announcements data.list_of_announcements.map(processAnnouncement)
)
return annList.map(ann => ({
...ann,
lat: ann.latitude,
lng: ann.longtitude,
bestBy: ann.best_by,
bookedBy: ann.booked_by,
userId: ann.user_id
}))
}
export { initialAnnouncements, composeAnnouncementsURL, processAnnouncements } export { initialAnnouncements, composeAnnouncementsURL, processAnnouncements }