@@ -9,28 +9,27 @@ export async function GET() {
9
9
`${ process . env . NEXT_PUBLIC_NGINX } /${ process . env . NEXT_PUBLIC_QUESTION_SERVICE } /questions` ,
10
10
{
11
11
method : "GET" ,
12
- headers : generateAuthHeaders ( )
13
- }
12
+ headers : generateAuthHeaders ( ) ,
13
+ } ,
14
14
) ;
15
15
if ( ! response . ok ) {
16
16
return NextResponse . json (
17
17
{
18
18
error : await response . text ( ) ,
19
- status : response . status
19
+ status : response . status ,
20
20
} ,
21
- { status : response . status }
21
+ { status : response . status } ,
22
22
) ;
23
23
}
24
24
return response ;
25
25
} catch ( err : any ) {
26
26
return NextResponse . json (
27
27
{ error : err . message , status : 400 } ,
28
- { status : 400 }
28
+ { status : 400 } ,
29
29
) ;
30
30
}
31
31
}
32
32
33
-
34
33
export async function PUT ( request : NextRequest ) {
35
34
const body = ( await request . json ( ) ) as Question ;
36
35
try {
@@ -39,26 +38,29 @@ export async function PUT(request: NextRequest) {
39
38
{
40
39
method : "PUT" ,
41
40
body : JSON . stringify ( body ) ,
42
- headers : generateJSONHeaders ( )
43
- }
41
+ headers : generateJSONHeaders ( ) ,
42
+ } ,
44
43
) ;
45
44
if ( response . ok ) {
45
+ revalidatePath ( "/questions" ) ;
46
+ revalidatePath ( `/questions/${ body . id } ` ) ;
47
+ revalidatePath ( `/questions/edit/${ body . title } ` ) ;
46
48
return NextResponse . json (
47
49
{ status : response . status } ,
48
- { status : response . status }
50
+ { status : response . status } ,
49
51
) ;
50
52
}
51
53
return NextResponse . json (
52
54
{
53
55
error : ( await response . json ( ) ) [ "Error adding question: " ] ,
54
- status : response . status
56
+ status : response . status ,
55
57
} ,
56
- { status : response . status }
58
+ { status : response . status } ,
57
59
) ;
58
60
} catch ( err : any ) {
59
61
return NextResponse . json (
60
62
{ error : err . message , status : 400 } ,
61
- { status : 400 }
63
+ { status : 400 } ,
62
64
) ;
63
65
}
64
66
}
@@ -71,26 +73,27 @@ export async function POST(request: NextRequest) {
71
73
{
72
74
method : "POST" ,
73
75
body : JSON . stringify ( body ) ,
74
- headers : generateJSONHeaders ( )
75
- }
76
+ headers : generateJSONHeaders ( ) ,
77
+ } ,
76
78
) ;
77
79
if ( response . ok ) {
80
+ revalidatePath ( "/questions" ) ;
78
81
return NextResponse . json (
79
82
{ status : response . status } ,
80
- { status : response . status }
83
+ { status : response . status } ,
81
84
) ;
82
85
}
83
86
return NextResponse . json (
84
87
{
85
88
error : ( await response . json ( ) ) [ "Error adding question: " ] ,
86
- status : response . status
89
+ status : response . status ,
87
90
} ,
88
- { status : response . status }
91
+ { status : response . status } ,
89
92
) ;
90
93
} catch ( err : any ) {
91
94
return NextResponse . json (
92
95
{ error : err . message , status : 400 } ,
93
- { status : 400 }
96
+ { status : 400 } ,
94
97
) ;
95
98
}
96
99
}
@@ -100,16 +103,16 @@ export async function DELETE(request: NextRequest) {
100
103
if ( body . qid === undefined ) {
101
104
return NextResponse . json (
102
105
{ error : "No ID specified." , status : 400 } ,
103
- { status : 400 }
106
+ { status : 400 } ,
104
107
) ;
105
108
}
106
109
try {
107
110
const response = await fetch (
108
111
`${ process . env . NEXT_PUBLIC_NGINX } /${ process . env . NEXT_PUBLIC_QUESTION_SERVICE } /questions/delete/${ body . qid } ` ,
109
112
{
110
113
method : "DELETE" ,
111
- headers : generateAuthHeaders ( )
112
- }
114
+ headers : generateAuthHeaders ( ) ,
115
+ } ,
113
116
) ;
114
117
if ( response . ok ) {
115
118
// NextResponse doesn't support 204.
@@ -119,14 +122,14 @@ export async function DELETE(request: NextRequest) {
119
122
return NextResponse . json (
120
123
{
121
124
error : ( await response . json ( ) ) [ "Error deleting question: " ] ,
122
- status : response . status
125
+ status : response . status ,
123
126
} ,
124
- { status : response . status }
127
+ { status : response . status } ,
125
128
) ;
126
129
} catch ( err : any ) {
127
130
return NextResponse . json (
128
131
{ error : `Bad request: ${ err . message } ` , status : 400 } ,
129
- { status : 400 }
132
+ { status : 400 } ,
130
133
) ;
131
134
}
132
135
}
0 commit comments