Updated announcement fetching to new response schema

This commit is contained in:
Dmitriy Shishkov 2023-08-08 12:07:12 +03:00
parent e1e1244b3a
commit c52a623907
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
3 changed files with 6 additions and 12 deletions

View File

@ -6,7 +6,7 @@ type AnnouncementResponse = {
user_id: number,
name: string,
category: Category,
best_by: number,
best_by: string,
address: string,
longtitude: number,
latitude: number,
@ -23,7 +23,7 @@ const isAnnouncementResponse = (obj: unknown): obj is AnnouncementResponse => (
'user_id': 'number',
'name': 'string',
'category': isCategory,
'best_by': 'number',
'best_by': 'string',
'address': 'string',
'longtitude': 'number',
'latitude': 'number',

View File

@ -11,7 +11,7 @@ const composeAnnouncementsURL = (filters: FiltersType) => (
)
const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => (
data.list_of_announcements.map(processAnnouncement)
data.map(processAnnouncement)
)
export { initialAnnouncements, composeAnnouncementsURL, processAnnouncements }

View File

@ -1,16 +1,10 @@
import { isArrayOf, isObject } from '../../utils/types'
import { isArrayOf } from '../../utils/types'
import { AnnouncementResponse, isAnnouncementResponse } from '../announcement/types'
type AnnouncementsResponse = {
list_of_announcements: AnnouncementResponse[],
Success: boolean,
}
type AnnouncementsResponse = AnnouncementResponse[]
const isAnnouncementsResponse = (obj: unknown): obj is AnnouncementsResponse => (
isObject(obj, {
'list_of_announcements': obj => isArrayOf<AnnouncementResponse>(obj, isAnnouncementResponse),
'Success': 'boolean',
})
isArrayOf<AnnouncementResponse>(obj, isAnnouncementResponse)
)
export type {