From 4135c291605747d2b752cc64bbfc2e99c0e9ed24 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Tue, 8 Aug 2023 18:18:57 +0300 Subject: [PATCH] Fixed announcement typing Expired -> obsolete filter front Removed useless despose utils --- front/src/api/announcement/types.ts | 38 ++++++++++++----------------- front/src/assets/userCategories.ts | 6 ++--- front/src/utils/dispose.ts | 9 ------- front/src/utils/filters.ts | 8 +++--- 4 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 front/src/utils/dispose.ts diff --git a/front/src/api/announcement/types.ts b/front/src/api/announcement/types.ts index 449fc6f..a00697c 100644 --- a/front/src/api/announcement/types.ts +++ b/front/src/api/announcement/types.ts @@ -1,20 +1,28 @@ import { isObject } from '../../utils/types' import { Category, isCategory } from '../../assets/category' -type AnnouncementResponse = { +type Announcement = { id: number, - user_id: number, + userId: number, name: string, category: Category, - best_by: string, + bestBy: string, address: string, - longtitude: number, - latitude: number, - description: string, + lng: number, + lat: number, + description: string | null, src: string | null, metro: string, trashId: number | null, - booked_by: number, + bookedBy: number, +} + +type AnnouncementResponse = Omit & { + 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 => ( @@ -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 { Announcement, AnnouncementResponse, diff --git a/front/src/assets/userCategories.ts b/front/src/assets/userCategories.ts index ae4b485..f98a907 100644 --- a/front/src/assets/userCategories.ts +++ b/front/src/assets/userCategories.ts @@ -16,18 +16,18 @@ const userCategoriesInfos: Record string> = `Годен до ${new Date(ann.bestBy).toLocaleDateString('ru')}` ), needDispose: (ann: Announcement) => ( - `Были заинтересованы: ${ann.bookedBy} чел.` + `Было заинтересно ${ann.bookedBy} чел.` ), } const composeUserCategoriesFilters: Record FiltersType> = { givingOut: () => ({ userId: getId(), - expired: false, + obsolete: false, }), needDispose: () => ({ userId: getId(), - expired: true, + obsolete: true, }), } diff --git a/front/src/utils/dispose.ts b/front/src/utils/dispose.ts deleted file mode 100644 index 65a87ff..0000000 --- a/front/src/utils/dispose.ts +++ /dev/null @@ -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 } diff --git a/front/src/utils/filters.ts b/front/src/utils/filters.ts index bbad2e7..131f5de 100644 --- a/front/src/utils/filters.ts +++ b/front/src/utils/filters.ts @@ -2,17 +2,17 @@ import { Announcement } from '../api/announcement/types' import { isCategory } from '../assets/category' 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 FiltersType = Partial< Pick & { - 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) => ( Object.fromEntries( @@ -39,7 +39,7 @@ const URLDecoreFilters = (params: URLSearchParams): FiltersType => { userId: fallbackToUndefined(Number.parseInt(strFilters['userId']), isInt), category: fallbackToUndefined(strFilters['category'], isCategory), metro: strFilters['metro'], - expired: fallbackToUndefined(strFilters['expired'] === 'true', isBoolean), + obsolete: fallbackToUndefined(strFilters['obsolete'] === 'true', isBoolean), } }