From c1b5865feb76295c2e1fcf6ba02164292a85fc61 Mon Sep 17 00:00:00 2001 From: echo Date: Sat, 10 Jan 2026 20:16:08 +0100 Subject: [PATCH] article detail page db error fixed --- backend/src/modules/entities.ts | 20 +++++- frontend/src/routes.tsx | 110 ++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 6 deletions(-) diff --git a/backend/src/modules/entities.ts b/backend/src/modules/entities.ts index 2047e4f..18af08b 100644 --- a/backend/src/modules/entities.ts +++ b/backend/src/modules/entities.ts @@ -6,8 +6,22 @@ import { UpdateDateColumn, ManyToOne, JoinColumn, + ValueTransformer, } from 'typeorm'; +class ArrayTransformer implements ValueTransformer { + to(value: string[]): string { + return JSON.stringify(value ?? []); + } + from(value: string): string[] { + try { + return value ? JSON.parse(value) : []; + } catch { + return []; + } + } +} + export enum ArticleStatus { DRAFT = 'draft', PUBLISHED = 'published', @@ -92,7 +106,11 @@ export class Article { @Column({ default: '' }) featuredImage: string; - @Column({ type: 'text', default: '[]' }) + @Column({ + type: 'text', + default: '[]', + transformer: new ArrayTransformer(), + }) tags: string[]; @Column({ diff --git a/frontend/src/routes.tsx b/frontend/src/routes.tsx index 7d9fadf..a0a6418 100644 --- a/frontend/src/routes.tsx +++ b/frontend/src/routes.tsx @@ -17,7 +17,7 @@ const rootRoute = createRootRoute({

- Placebo.mk + Placebo.mk

@@ -200,7 +201,106 @@ const articlesRoute = createRoute({ }, }) -const routeTree = rootRoute.addChildren([indexRoute, articlesRoute]) +const articleDetailRoute = createRoute({ + getParentRoute: () => rootRoute, + path: '/articles/$id', + component: () => { + const { id } = articleDetailRoute.useParams() + const { data, isLoading, error } = useQuery({ + queryKey: ['article', id], + queryFn: () => api.fetchArticleById(id), + }) + + if (isLoading) { + return ( +
+
Loading article...
+
+ ) + } + + if (error) { + return ( +
+
Error loading article
+
+ ) + } + + if (!data) { + return ( +
+
Article not found
+
+ ) + } + + return ( +
+ + + + + + Back to articles + + +

{data.title}

+ +
+ + {new Date(data.createdAt).toLocaleDateString('mk-MK', { + day: 'numeric', + month: 'long', + year: 'numeric', + })} + + + {data.views} views + {data.author && ( + <> + + By {data.author.name} + + )} +
+ + {data.featuredImage && ( + {data.title} + )} + +
+

{data.content}

+
+ + {data.tags && Array.isArray(data.tags) && data.tags.length > 0 && ( +
+

Tags

+
+ {data.tags.map((tag) => ( + + {tag} + + ))} +
+
+ )} +
+ ) + }, +}) + +const routeTree = rootRoute.addChildren([indexRoute, articlesRoute, articleDetailRoute]) export const router = createRouter({ routeTree })