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, user_id: number,
name: string, name: string,
category: Category, category: Category,
best_by: number, best_by: string,
address: string, address: string,
longtitude: number, longtitude: number,
latitude: number, latitude: number,
@ -23,7 +23,7 @@ const isAnnouncementResponse = (obj: unknown): obj is AnnouncementResponse => (
'user_id': 'number', 'user_id': 'number',
'name': 'string', 'name': 'string',
'category': isCategory, 'category': isCategory,
'best_by': 'number', 'best_by': 'string',
'address': 'string', 'address': 'string',
'longtitude': 'number', 'longtitude': 'number',
'latitude': 'number', 'latitude': 'number',

View File

@ -11,7 +11,7 @@ const composeAnnouncementsURL = (filters: FiltersType) => (
) )
const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => ( const processAnnouncements = (data: AnnouncementsResponse): Announcement[] => (
data.list_of_announcements.map(processAnnouncement) data.map(processAnnouncement)
) )
export { initialAnnouncements, composeAnnouncementsURL, processAnnouncements } 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' import { AnnouncementResponse, isAnnouncementResponse } from '../announcement/types'
type AnnouncementsResponse = { type AnnouncementsResponse = AnnouncementResponse[]
list_of_announcements: AnnouncementResponse[],
Success: boolean,
}
const isAnnouncementsResponse = (obj: unknown): obj is AnnouncementsResponse => ( const isAnnouncementsResponse = (obj: unknown): obj is AnnouncementsResponse => (
isObject(obj, { isArrayOf<AnnouncementResponse>(obj, isAnnouncementResponse)
'list_of_announcements': obj => isArrayOf<AnnouncementResponse>(obj, isAnnouncementResponse),
'Success': 'boolean',
})
) )
export type { export type {