Skip to content

Commit 1b2d405

Browse files
authored
Merge pull request #38 from techdiary-dev/comment
Comment
2 parents 5558153 + e02bbd7 commit 1b2d405

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

src/app/dashboard/_components/MatrixReport.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Card, CardContent } from "@/components/ui/card";
55
import { useTranslation } from "@/i18n/use-translation";
66
import { useQuery } from "@tanstack/react-query";
77
import { LoaderIcon } from "lucide-react";
8-
import React from "react";
8+
import React, { useEffect } from "react";
99

1010
const MatrixReport = () => {
1111
const { _t } = useTranslation();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import z from "zod";
2+
import { CommentActionInput } from "./inputs/comment.input";
3+
4+
export const getComments = async (
5+
resourceId: string,
6+
resourceType: "ARTICLE" | "COMMENT"
7+
) => {
8+
// Fetch comments from the database based on resourceId and resourceType
9+
// const comments = await db
10+
// .select()
11+
// .from(commentsTable)
12+
// .where(commentsTable.resource_id.eq(resourceId))
13+
// .and(commentsTable.resource_type.eq(resourceType))
14+
// .orderBy(commentsTable.created_at.desc());
15+
// return comments;
16+
return []; // Placeholder for actual database query
17+
};
18+
19+
export const createComment = async (
20+
input: z.infer<typeof CommentActionInput.create>
21+
) => {
22+
const { resource_id, resource_type, body } = input;
23+
24+
// Create the comment in the database
25+
26+
// return newComment[0];
27+
};
28+
29+
export const deleteComment = async (
30+
input: z.infer<typeof CommentActionInput.delete>
31+
) => {
32+
const { id } = input;
33+
34+
// Delete the comment from the database
35+
// await db.delete(commentsTable).where(commentsTable.id.eq(id));
36+
37+
// return { success: true };
38+
};

src/backend/services/dashboard.action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

3-
import * as sessionActions from "@/backend/services/session.actions";
43
import { pgClient } from "@/backend/persistence/clients";
4+
import { authID } from "@/backend/services/session.actions";
55

66
const sql = String.raw;
77

@@ -12,15 +12,15 @@ SELECT (SELECT Count(*)
1212
AS total_articles,
1313
(SELECT Count(*)
1414
FROM comments
15-
WHERE comments.commentable_type = 'ARTICLE'
16-
AND comments.commentable_id IN (SELECT id
15+
WHERE comments.resource_type = 'ARTICLE'
16+
AND comments.resource_id IN (SELECT id
1717
FROM articles
1818
WHERE articles.author_id = $1))
1919
AS total_comments
2020
`;
2121

2222
export async function myArticleMatrix() {
23-
const sessionUserId = await sessionActions.authID();
23+
const sessionUserId = await authID();
2424

2525
const totalPostsQuery = await pgClient?.executeSQL<any>(query, [
2626
sessionUserId!,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import z from "zod";
2+
3+
export const CommentActionInput = {
4+
create: z.object({
5+
resource_id: z.string().uuid(),
6+
resource_type: z.enum(["ARTICLE", "COMMENT"]),
7+
body: z.string().min(1).max(500),
8+
}),
9+
update: z.object({
10+
id: z.string().uuid(),
11+
body: z.string().min(1).max(500),
12+
}),
13+
delete: z.object({
14+
id: z.string().uuid(),
15+
}),
16+
};

0 commit comments

Comments
 (0)