|
1 | | -import { Article, ArticleTag, Tag, User } from "@/backend/models/domain-models"; |
2 | | -import { persistenceRepository } from "@/backend/persistence-repositories"; |
| 1 | +import { Tag } from "@/backend/models/domain-models"; |
3 | 2 | import { DatabaseTableName } from "@/backend/persistence/persistence-contracts"; |
4 | | -import { |
5 | | - and, |
6 | | - eq, |
7 | | - inArray, |
8 | | - leftJoin, |
9 | | -} from "@/backend/persistence/persistence-where-operator"; |
| 3 | +import { persistenceRepository } from "@/backend/persistence/persistence-repositories"; |
10 | 4 | import * as sessionActions from "@/backend/services/session.actions"; |
11 | 5 | import ArticleEditor from "@/components/Editor/ArticleEditor"; |
12 | 6 | import { notFound } from "next/navigation"; |
13 | 7 | import React from "react"; |
| 8 | +import { and, eq, inArray } from "sqlkit"; |
14 | 9 |
|
15 | 10 | interface Props { |
16 | 11 | params: Promise<{ uuid: string }>; |
17 | 12 | } |
18 | 13 | const page: React.FC<Props> = async ({ params }) => { |
19 | 14 | const sessionUserId = await sessionActions.getSessionUserId(); |
| 15 | + |
20 | 16 | const _params = await params; |
21 | | - // eq("author_id", sessionUserId) |
22 | | - const [article] = await persistenceRepository.article.findRows({ |
| 17 | + |
| 18 | + const [article] = await persistenceRepository.article.find({ |
23 | 19 | limit: 1, |
24 | | - where: and(eq("id", _params.uuid), eq("author_id", sessionUserId)), |
| 20 | + where: and(eq("id", _params.uuid), eq("author_id", sessionUserId!)), |
25 | 21 | joins: [ |
26 | | - leftJoin<Article, User>({ |
| 22 | + { |
27 | 23 | as: "author", |
28 | | - joinTo: DatabaseTableName.users, |
29 | | - localField: "author_id", |
30 | | - foreignField: "id", |
| 24 | + table: DatabaseTableName.users, |
| 25 | + type: "left", |
| 26 | + on: { |
| 27 | + localField: "author_id", |
| 28 | + foreignField: "id", |
| 29 | + }, |
31 | 30 | columns: ["id", "name", "username"], |
32 | | - }), |
| 31 | + }, |
33 | 32 | ], |
34 | 33 | }); |
35 | 34 |
|
36 | | - const aggregatedTags = await persistenceRepository.articleTag.findRows({ |
| 35 | + const aggregatedTags = await persistenceRepository.articleTag.find({ |
37 | 36 | where: inArray("article_id", [article.id]), |
38 | 37 | joins: [ |
39 | | - leftJoin<ArticleTag, Tag>({ |
| 38 | + { |
40 | 39 | as: "tag", |
41 | | - joinTo: "tags", |
42 | | - localField: "tag_id", |
43 | | - foreignField: "id", |
| 40 | + table: "tags", |
| 41 | + type: "left", |
| 42 | + on: { |
| 43 | + localField: "tag_id", |
| 44 | + foreignField: "id", |
| 45 | + }, |
44 | 46 | columns: ["id", "name", "color", "icon", "description"], |
45 | | - }), |
| 47 | + }, |
46 | 48 | ], |
47 | 49 | }); |
48 | 50 |
|
|
0 commit comments