diff --git a/front/src/api/announcement/index.ts b/front/src/api/announcement/index.ts index e69de29..d84eb44 100644 --- a/front/src/api/announcement/index.ts +++ b/front/src/api/announcement/index.ts @@ -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 } diff --git a/front/src/api/announcements/index.ts b/front/src/api/announcements/index.ts index 2e7c3d7..9b5f79c 100644 --- a/front/src/api/announcements/index.ts +++ b/front/src/api/announcements/index.ts @@ -1,5 +1,6 @@ import { API_URL } from '../../config' import { FiltersType, URLEncodeFilters } from '../../utils/filters' +import { processAnnouncement } from '../announcement' import { Announcement } from '../announcement/types' import { AnnouncementsResponse } from './types' @@ -9,17 +10,8 @@ const composeAnnouncementsURL = (filters: FiltersType) => ( API_URL + '/announcements?' + new URLSearchParams(URLEncodeFilters(filters)).toString() ) -const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => { - const annList = data.list_of_announcements - - return annList.map(ann => ({ - ...ann, - lat: ann.latitude, - lng: ann.longtitude, - bestBy: ann.best_by, - bookedBy: ann.booked_by, - userId: ann.user_id - })) -} +const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => ( + data.list_of_announcements.map(processAnnouncement) +) export { initialAnnouncements, composeAnnouncementsURL, processAnnouncements }