-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: comment and replace function in repository service
- Loading branch information
1 parent
59c32f7
commit 80eba83
Showing
28 changed files
with
371 additions
and
629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,23 @@ | ||
"use server"; | ||
import { userAction } from "@/lib/next-safe-action"; | ||
import repositoryService from "@/services/repository.service"; | ||
import { pusherServer } from "@/lib/pusherServer"; | ||
import * as z from "zod"; | ||
// "use server"; | ||
// import { userAction } from "@/lib/next-safe-action"; | ||
// import { postRepositoryComment } from "@/services/repository.service"; | ||
// import * as z from "zod"; | ||
|
||
const schema = z.object({ | ||
repositoryId: z.number(), | ||
picture: z.string().optional().nullable(), | ||
name: z.string().optional().nullable(), | ||
username: z.string().optional().nullable(), | ||
content: z.string().min(1, "Comment must be at least 1 character long"), | ||
}); | ||
// const schema = z.object({ | ||
// repositoryId: z.number(), | ||
// picture: z.string().optional().nullable(), | ||
// name: z.string().optional().nullable(), | ||
// username: z.string().optional().nullable(), | ||
// content: z.string().min(1, "Comment must be at least 1 character long"), | ||
// }); | ||
|
||
export const addComment = userAction(schema, async (data, ctx) => { | ||
try { | ||
await pusherServer.trigger(`repo-${data.repositoryId}`, "new-comment", { | ||
// content: data.content, | ||
// picture: data.picture, | ||
// name: data.name, | ||
// username: data.username, | ||
// userId: ctx.session.user.id, | ||
content: data.content, | ||
createdBy: { | ||
image: data.picture, | ||
name: data.name, | ||
username: data.username, | ||
}, | ||
createdAt: new Date(), | ||
userId: ctx.session.user.id, | ||
}); | ||
|
||
await repositoryService.addCommentToRepository( | ||
data.repositoryId, | ||
data.content, | ||
ctx.session.user.id, | ||
); | ||
} catch (error) { | ||
if (error instanceof Error) return { error: error.message }; | ||
} | ||
}); | ||
// export const addComment = userAction(schema, async (data, ctx) => { | ||
// try { | ||
// await postRepositoryComment({ | ||
// repositoryId: data.repositoryId, | ||
// content: data.content, | ||
// }); | ||
// } catch (error) { | ||
// if (error instanceof Error) return { error: error.message }; | ||
// } | ||
// }); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.