From 43976c1165ab6e6c03154f14dd0c323c95d7c840 Mon Sep 17 00:00:00 2001 From: DDeviak <117632082+DDeviak@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:12:09 +0300 Subject: [PATCH 1/2] chore: Removed image from News object as it is have to be already uploaded --- .../AdminPage/NewsPage/NewsModal/NewsModal.component.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/features/AdminPage/NewsPage/NewsModal/NewsModal.component.tsx b/src/features/AdminPage/NewsPage/NewsModal/NewsModal.component.tsx index 4b8ac15ce..6974cf77f 100644 --- a/src/features/AdminPage/NewsPage/NewsModal/NewsModal.component.tsx +++ b/src/features/AdminPage/NewsPage/NewsModal/NewsModal.component.tsx @@ -203,7 +203,6 @@ const NewsModal: React.FC<{ if (newsItem) { news.id = newsItem.id; news.imageId = imageId.current as number; - news.image = image.current; await newsStore.updateNews(news); } else { From 2e81896eeef8c937762647045d43e180d3289299 Mon Sep 17 00:00:00 2001 From: DDeviak <117632082+DDeviak@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:24:00 +0300 Subject: [PATCH 2/2] chore: Refactor NewsApi to use separate interfaces for create and update operations --- src/app/api/news/news.api.ts | 6 +++--- src/models/news/news.model.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/app/api/news/news.api.ts b/src/app/api/news/news.api.ts index 2760d6985..a5da70f82 100644 --- a/src/app/api/news/news.api.ts +++ b/src/app/api/news/news.api.ts @@ -1,6 +1,6 @@ import Agent from '@api/agent.api'; import { API_ROUTES } from '@constants/api-routes.constants'; -import News, { NewsWithUrl } from '@models/news/news.model'; +import News, { NewsWithUrl, NewsCreate, NewsUpdate } from '@models/news/news.model'; const NewsApi = { getById: (id: number) => Agent.get(`${API_ROUTES.NEWS.GET}/${id}`), @@ -21,11 +21,11 @@ const NewsApi = { )), ), - create: (news: News) => Agent.post(`${API_ROUTES.NEWS.CREATE}`, news), + create: (news: NewsCreate) => Agent.post(`${API_ROUTES.NEWS.CREATE}`, news), delete: (id: number) => Agent.delete(`${API_ROUTES.NEWS.DELETE}/${id}`), - update: (news: News) => Agent.put(`${API_ROUTES.NEWS.UPDATE}`, news), + update: (news: NewsUpdate) => Agent.put(`${API_ROUTES.NEWS.UPDATE}`, news), }; export default NewsApi; diff --git a/src/models/news/news.model.ts b/src/models/news/news.model.ts index 295c3e08d..64e73555d 100644 --- a/src/models/news/news.model.ts +++ b/src/models/news/news.model.ts @@ -1,16 +1,22 @@ import Image from '@models/media/image.model'; import dayjs from 'dayjs'; -export default interface News { - id: number; +export interface NewsCreate { title: string; text: string; url: string; imageId: number; - image?: Image; creationDate: dayjs.Dayjs; } +export interface NewsUpdate extends NewsCreate { + id: number; +} + +export default interface News extends NewsUpdate { + image?: Image; +} + export interface RandomNews { title: string; randomNewsUrl: string;