File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 1
1
"use client" ;
2
- import useUser from "app/hooks/useUser" ;
3
2
import { Button } from "@/components/ui/button" ;
4
3
import { Input } from "@/components/ui/input" ;
5
4
import { useRouter } from "next/navigation" ;
@@ -9,8 +8,9 @@ import toast from "react-hot-toast";
9
8
10
9
interface CourseReviewProps {
11
10
id : number ;
11
+ auth_id : string ;
12
12
}
13
- const CourseReview = ( { id } : CourseReviewProps ) => {
13
+ const CourseReview = ( { id, auth_id } : CourseReviewProps ) => {
14
14
const {
15
15
register,
16
16
handleSubmit,
@@ -21,7 +21,6 @@ const CourseReview = ({ id }: CourseReviewProps) => {
21
21
authorId : 0 ,
22
22
} ,
23
23
} ) ;
24
- const { user } = useUser ( ) ;
25
24
const router = useRouter ( ) ;
26
25
const [ isLoading , setIsLoading ] = useState ( false ) ;
27
26
@@ -36,8 +35,8 @@ const CourseReview = ({ id }: CourseReviewProps) => {
36
35
method : "POST" ,
37
36
body : JSON . stringify ( {
38
37
title : data . title ,
39
- id : Number ( id ) ,
40
- authorId : user ?. id ,
38
+ planId : Number ( id ) ,
39
+ auth_id : auth_id ,
41
40
} ) ,
42
41
headers : {
43
42
"Content-Type" : "application/json" ,
Original file line number Diff line number Diff line change @@ -3,19 +3,32 @@ import prisma from "utils/prisma/prismaClient";
3
3
4
4
export const POST = async ( req : Request ) => {
5
5
try {
6
- const { title, id , authorId } = await req . json ( ) ;
6
+ const { title, planId , auth_id } = await req . json ( ) ;
7
7
8
8
await prisma . $connect ( ) ;
9
+
10
+ const author = await prisma . user . findUnique ( {
11
+ where : {
12
+ auth_id : auth_id ,
13
+ } ,
14
+ select : {
15
+ id : true ,
16
+ } ,
17
+ } ) ;
18
+
9
19
const post = await prisma . post . create ( {
10
20
data : {
11
21
title : title ,
12
- planId : id ,
13
- authorId : authorId ,
22
+ planId : planId ,
23
+ authorId : author ?. id ,
14
24
} ,
15
25
} ) ;
16
26
return NextResponse . json ( { message : "Success" , post } , { status : 201 } ) ;
17
27
} catch ( error ) {
18
- return NextResponse . json ( { message : "Error" , error } , { status : 500 } ) ;
28
+ return NextResponse . json (
29
+ { message : "エラーが発生しました" , error } ,
30
+ { status : 500 }
31
+ ) ;
19
32
} finally {
20
33
await prisma . $disconnect ( ) ;
21
34
}
You can’t perform that action at this time.
0 commit comments