@@ -20,19 +20,18 @@ export async function GET(
20
20
const params = await props . params ;
21
21
const session = await getServerSession ( ) ;
22
22
23
- if ( isAdmin ( session ?. user ?. email || "" ) ) {
24
- // Signed in
25
- const notificationId = params . notificationId ;
26
- try {
27
- const notificationItem =
28
- await getNotificationByNotificationId ( notificationId ) ;
29
- return NextResponse . json ( notificationItem ) ;
30
- } catch ( e ) {
31
- logger . error ( e ) ;
32
- return NextResponse . json ( { success : false } , { status : 500 } ) ;
33
- }
34
- } else {
35
- return NextResponse . json ( { success : false } , { status : 401 } ) ;
23
+ if ( ! isAdmin ( session ?. user ?. email || "" ) ) {
24
+ return NextResponse . json ( { error : "Not an admin user" } , { status : 401 } ) ;
25
+ }
26
+
27
+ const notificationId = params . notificationId ;
28
+ try {
29
+ const notificationItem =
30
+ await getNotificationByNotificationId ( notificationId ) ;
31
+ return NextResponse . json ( notificationItem ) ;
32
+ } catch ( e ) {
33
+ logger . error ( e ) ;
34
+ return NextResponse . json ( { success : false } , { status : 500 } ) ;
36
35
}
37
36
}
38
37
@@ -44,18 +43,17 @@ export async function DELETE(
44
43
) {
45
44
const params = await props . params ;
46
45
const session = await getServerSession ( ) ;
47
- if ( isAdmin ( session ?. user ?. email || "" ) ) {
48
- // Signed in
49
- const notificationId = params . notificationId ;
50
- try {
51
- const notificationItem = await deleteNotification ( notificationId ) ;
52
- return NextResponse . json ( notificationItem ) ;
53
- } catch ( e ) {
54
- logger . error ( e ) ;
55
- return NextResponse . json ( { success : false } , { status : 500 } ) ;
56
- }
57
- } else {
58
- return NextResponse . json ( { success : false } , { status : 401 } ) ;
46
+ if ( ! isAdmin ( session ?. user ?. email || "" ) ) {
47
+ return NextResponse . json ( { error : "Not an admin user" } , { status : 401 } ) ;
48
+ }
49
+
50
+ const notificationId = params . notificationId ;
51
+ try {
52
+ const notificationItem = await deleteNotification ( notificationId ) ;
53
+ return NextResponse . json ( notificationItem ) ;
54
+ } catch ( e ) {
55
+ logger . error ( e ) ;
56
+ return NextResponse . json ( { success : false } , { status : 500 } ) ;
59
57
}
60
58
}
61
59
@@ -66,24 +64,22 @@ export async function PUT(
66
64
const params = await props . params ;
67
65
const { notificationId } = params ;
68
66
const session = await getServerSession ( ) ;
67
+ if ( ! isAdmin ( session ?. user ?. email || "" ) ) {
68
+ return NextResponse . json ( { error : "Not an admin user" } , { status : 401 } ) ;
69
+ }
70
+ try {
71
+ const updatedData : NotificationRow = await req . json ( ) ;
72
+ const updatedNotification = await updateNotification (
73
+ notificationId ,
74
+ updatedData ,
75
+ ) ;
69
76
70
- if ( isAdmin ( session ?. user ?. email || "" ) ) {
71
- try {
72
- const updatedData : NotificationRow = await req . json ( ) ;
73
- const updatedNotification = await updateNotification (
74
- notificationId ,
75
- updatedData ,
76
- ) ;
77
-
78
- return NextResponse . json ( updatedNotification , { status : 200 } ) ;
79
- } catch ( error ) {
80
- console . error ( "Error updating notification:" , error ) ;
81
- return NextResponse . json (
82
- { error : "Internal Server Error" } ,
83
- { status : 500 } ,
84
- ) ;
85
- }
86
- } else {
87
- return NextResponse . json ( { success : false } , { status : 401 } ) ;
77
+ return NextResponse . json ( updatedNotification , { status : 200 } ) ;
78
+ } catch ( error ) {
79
+ console . error ( "Error updating notification:" , error ) ;
80
+ return NextResponse . json (
81
+ { error : "Internal Server Error" } ,
82
+ { status : 500 } ,
83
+ ) ;
88
84
}
89
85
}
0 commit comments