Refactoring API types and Dates now working.
This commit is contained in:
parent
86a7471656
commit
509f5292fc
@ -1,5 +1,5 @@
|
|||||||
import { ApiError } from './ApiError'
|
import { ApiError } from './ApiError'
|
||||||
import { RecipeInfosView } from './types/RecipeInfosView'
|
import RecipeInfosView, { RawRecipeInfosView } from './types/RecipeInfosView'
|
||||||
|
|
||||||
const getRecipeInfos = async (
|
const getRecipeInfos = async (
|
||||||
token: string | null,
|
token: string | null,
|
||||||
@ -19,7 +19,45 @@ const getRecipeInfos = async (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return (await response.json()) as RecipeInfosView
|
const { pageNumber, pageSize, content } =
|
||||||
|
(await response.json()) as RawRecipeInfosView
|
||||||
|
return {
|
||||||
|
pageNumber,
|
||||||
|
pageSize,
|
||||||
|
content: content.map(
|
||||||
|
({
|
||||||
|
id,
|
||||||
|
updated: rawUpdated,
|
||||||
|
title,
|
||||||
|
ownerId,
|
||||||
|
ownerUsername,
|
||||||
|
isPublic,
|
||||||
|
starCount,
|
||||||
|
mainImage: rawMainImage
|
||||||
|
}) => ({
|
||||||
|
id,
|
||||||
|
updated: new Date(rawUpdated),
|
||||||
|
title,
|
||||||
|
ownerId,
|
||||||
|
ownerUsername,
|
||||||
|
isPublic,
|
||||||
|
starCount,
|
||||||
|
mainImage: {
|
||||||
|
url: rawMainImage.url,
|
||||||
|
created: new Date(rawMainImage.created),
|
||||||
|
modified: rawMainImage.modified
|
||||||
|
? new Date(rawMainImage.modified)
|
||||||
|
: null,
|
||||||
|
filename: rawMainImage.fileName,
|
||||||
|
mimeType: rawMainImage.mimeType,
|
||||||
|
alt: rawMainImage.alt,
|
||||||
|
caption: rawMainImage.caption,
|
||||||
|
owner: rawMainImage.owner,
|
||||||
|
isPublic: rawMainImage.isPublic
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ApiError(response.status, response.statusText)
|
throw new ApiError(response.status, response.statusText)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
import UserInfoView from './UserInfoView'
|
import UserInfoView from './UserInfoView'
|
||||||
|
|
||||||
interface ImageView {
|
export interface RawImageView {
|
||||||
url: string
|
url: string
|
||||||
created: string
|
created: string
|
||||||
modified: string | null
|
modified: string | null
|
||||||
|
fileName: string
|
||||||
|
mimeType: string
|
||||||
|
alt: string | null
|
||||||
|
caption: string | null
|
||||||
|
owner: UserInfoView
|
||||||
|
isPublic: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImageView {
|
||||||
|
url: string
|
||||||
|
created: Date
|
||||||
|
modified: Date | null
|
||||||
filename: string
|
filename: string
|
||||||
mimeType: string
|
mimeType: string
|
||||||
alt: string | null
|
alt: string | null
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
import ImageView from './ImageView'
|
import ImageView, { RawImageView } from './ImageView'
|
||||||
|
|
||||||
export interface RecipeInfoView {
|
export interface RawRecipeInfoView {
|
||||||
|
id: number
|
||||||
|
updated: string
|
||||||
|
title: string
|
||||||
|
ownerId: number
|
||||||
|
ownerUsername: string
|
||||||
|
isPublic: boolean
|
||||||
|
starCount: number
|
||||||
|
mainImage: RawImageView
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RecipeInfoView {
|
||||||
id: number
|
id: number
|
||||||
updated: Date
|
updated: Date
|
||||||
title: string
|
title: string
|
||||||
@ -10,3 +21,5 @@ export interface RecipeInfoView {
|
|||||||
starCount: number
|
starCount: number
|
||||||
mainImage: ImageView
|
mainImage: ImageView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default RecipeInfoView
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
import { RecipeInfoView } from './types/RecipeInfoView'
|
import RecipeInfoView, { RawRecipeInfoView } from './RecipeInfoView'
|
||||||
|
|
||||||
export interface RecipeInfosView {
|
export interface RawRecipeInfosView {
|
||||||
|
pageNumber: number
|
||||||
|
pageSize: number
|
||||||
|
content: RawRecipeInfoView[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RecipeInfosView {
|
||||||
pageNumber: number
|
pageNumber: number
|
||||||
pageSize: number
|
pageSize: number
|
||||||
content: RecipeInfoView[]
|
content: RecipeInfoView[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default RecipeInfosView
|
||||||
|
Loading…
Reference in New Issue
Block a user