Fixed announcement typing
Expired -> obsolete filter front Removed useless despose utils
This commit is contained in:
parent
6c5c7aa0c2
commit
4135c29160
@ -1,20 +1,28 @@
|
|||||||
import { isObject } from '../../utils/types'
|
import { isObject } from '../../utils/types'
|
||||||
import { Category, isCategory } from '../../assets/category'
|
import { Category, isCategory } from '../../assets/category'
|
||||||
|
|
||||||
type AnnouncementResponse = {
|
type Announcement = {
|
||||||
id: number,
|
id: number,
|
||||||
user_id: number,
|
userId: number,
|
||||||
name: string,
|
name: string,
|
||||||
category: Category,
|
category: Category,
|
||||||
best_by: string,
|
bestBy: string,
|
||||||
address: string,
|
address: string,
|
||||||
longtitude: number,
|
lng: number,
|
||||||
latitude: number,
|
lat: number,
|
||||||
description: string,
|
description: string | null,
|
||||||
src: string | null,
|
src: string | null,
|
||||||
metro: string,
|
metro: string,
|
||||||
trashId: number | null,
|
trashId: number | null,
|
||||||
booked_by: number,
|
bookedBy: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
type AnnouncementResponse = Omit<Announcement, 'userId' | 'bestBy' | 'bookedBy' | 'lat' | 'lng'> & {
|
||||||
|
user_id: Announcement['userId'],
|
||||||
|
best_by: Announcement['bestBy'],
|
||||||
|
longtitude: Announcement['lng'],
|
||||||
|
latitude: Announcement['lat'],
|
||||||
|
booked_by: Announcement['bookedBy'],
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAnnouncementResponse = (obj: unknown): obj is AnnouncementResponse => (
|
const isAnnouncementResponse = (obj: unknown): obj is AnnouncementResponse => (
|
||||||
@ -35,22 +43,6 @@ const isAnnouncementResponse = (obj: unknown): obj is AnnouncementResponse => (
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
type Announcement = {
|
|
||||||
id: number,
|
|
||||||
userId: number,
|
|
||||||
name: string,
|
|
||||||
category: Category,
|
|
||||||
bestBy: number,
|
|
||||||
address: string,
|
|
||||||
lng: number,
|
|
||||||
lat: number,
|
|
||||||
description: string | null,
|
|
||||||
src: string | null,
|
|
||||||
metro: string,
|
|
||||||
trashId: number | null,
|
|
||||||
bookedBy: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
Announcement,
|
Announcement,
|
||||||
AnnouncementResponse,
|
AnnouncementResponse,
|
||||||
|
@ -16,18 +16,18 @@ const userCategoriesInfos: Record<UserCategory, (ann: Announcement) => string> =
|
|||||||
`Годен до ${new Date(ann.bestBy).toLocaleDateString('ru')}`
|
`Годен до ${new Date(ann.bestBy).toLocaleDateString('ru')}`
|
||||||
),
|
),
|
||||||
needDispose: (ann: Announcement) => (
|
needDispose: (ann: Announcement) => (
|
||||||
`Были заинтересованы: ${ann.bookedBy} чел.`
|
`Было заинтересно ${ann.bookedBy} чел.`
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
const composeUserCategoriesFilters: Record<UserCategory, () => FiltersType> = {
|
const composeUserCategoriesFilters: Record<UserCategory, () => FiltersType> = {
|
||||||
givingOut: () => ({
|
givingOut: () => ({
|
||||||
userId: getId(),
|
userId: getId(),
|
||||||
expired: false,
|
obsolete: false,
|
||||||
}),
|
}),
|
||||||
needDispose: () => ({
|
needDispose: () => ({
|
||||||
userId: getId(),
|
userId: getId(),
|
||||||
expired: true,
|
obsolete: true,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import { Announcement } from '../api/announcement/types'
|
|
||||||
|
|
||||||
const DAY_MS = 24 * 60 * 60 * 1000
|
|
||||||
|
|
||||||
const isAnnExpired = (ann: Announcement) => (
|
|
||||||
(ann.bestBy - Date.now()) < DAY_MS
|
|
||||||
)
|
|
||||||
|
|
||||||
export { isAnnExpired }
|
|
@ -2,17 +2,17 @@ import { Announcement } from '../api/announcement/types'
|
|||||||
import { isCategory } from '../assets/category'
|
import { isCategory } from '../assets/category'
|
||||||
import { fallbackToUndefined, isBoolean, isInt } from './types'
|
import { fallbackToUndefined, isBoolean, isInt } from './types'
|
||||||
|
|
||||||
const filterNames = ['userId', 'category', 'metro', 'expired'] as const
|
const filterNames = ['userId', 'category', 'metro', 'obsolete'] as const
|
||||||
type FilterNames = typeof filterNames[number]
|
type FilterNames = typeof filterNames[number]
|
||||||
|
|
||||||
type FiltersType = Partial<
|
type FiltersType = Partial<
|
||||||
Pick<Announcement, FilterNames & keyof Announcement> &
|
Pick<Announcement, FilterNames & keyof Announcement> &
|
||||||
{
|
{
|
||||||
expired: boolean,
|
obsolete: boolean,
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|
||||||
const defaultFilters: FiltersType = { userId: undefined, category: undefined, metro: undefined, expired: false }
|
const defaultFilters: FiltersType = { userId: undefined, category: undefined, metro: undefined, obsolete: false }
|
||||||
|
|
||||||
const URLEncodeFilters = (filters: FiltersType) => (
|
const URLEncodeFilters = (filters: FiltersType) => (
|
||||||
Object.fromEntries(
|
Object.fromEntries(
|
||||||
@ -39,7 +39,7 @@ const URLDecoreFilters = (params: URLSearchParams): FiltersType => {
|
|||||||
userId: fallbackToUndefined(Number.parseInt(strFilters['userId']), isInt),
|
userId: fallbackToUndefined(Number.parseInt(strFilters['userId']), isInt),
|
||||||
category: fallbackToUndefined(strFilters['category'], isCategory),
|
category: fallbackToUndefined(strFilters['category'], isCategory),
|
||||||
metro: strFilters['metro'],
|
metro: strFilters['metro'],
|
||||||
expired: fallbackToUndefined(strFilters['expired'] === 'true', isBoolean),
|
obsolete: fallbackToUndefined(strFilters['obsolete'] === 'true', isBoolean),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user