Skip to content

Commit e86b79f

Browse files
committed
Enhance article page functionality by integrating ArticleTag model to fetch associated tags for articles. Update the Article interface to include optional tag relationships, improving the article retrieval process. Refactor the page component to display tags in the ArticleEditor.
1 parent e1b20f0 commit e86b79f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/app/(dashboard-editor)/dashboard/articles/[uuid]/page.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
and,
1010
manyToManyJoin,
1111
leftJoin,
12+
inArray,
1213
} from "@/backend/persistence/persistence-where-operator";
13-
import { Article, Tag, User } from "@/backend/models/domain-models";
14+
import { Article, ArticleTag, Tag, User } from "@/backend/models/domain-models";
1415
import { DatabaseTableName } from "@/backend/persistence/persistence-contracts";
1516

1617
interface Props {
@@ -35,13 +36,30 @@ const page: React.FC<Props> = async ({ params }) => {
3536
],
3637
});
3738

39+
const aggregatedTags = await persistenceRepository.articleTag.findRows({
40+
where: inArray("article_id", [article.id]),
41+
columns: ["tag_id", "article_id"],
42+
joins: [
43+
leftJoin<ArticleTag, Tag>({
44+
as: "tag",
45+
joinTo: "tags",
46+
localField: "tag_id",
47+
foreignField: "id",
48+
columns: ["id", "name", "created_at"],
49+
}),
50+
],
51+
});
52+
53+
const tags = aggregatedTags?.map((item) => item?.tag);
54+
if (tags.length) {
55+
article.tags = tags as Tag[];
56+
}
57+
3858
if (!article) {
3959
throw notFound();
4060
}
4161

42-
return <pre>{JSON.stringify(article, null, 2)}</pre>;
43-
44-
// return <ArticleEditor uuid={_params.uuid} article={article} />;
62+
return <ArticleEditor uuid={_params.uuid} article={article} />;
4563
};
4664

4765
export default page;

src/backend/models/domain-models.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ export interface ArticleTag {
108108
tag_id: string;
109109
created_at: Date;
110110
updated_at: Date;
111+
112+
// Relationships
113+
article?: Article;
114+
tag?: Tag;
111115
}

0 commit comments

Comments
 (0)