mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-04-11 20:54:31 +00:00
Add functionality to delete comment from notification
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m10s
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m10s
This commit is contained in:
parent
dae3c59c81
commit
c796a544ab
@ -21,8 +21,16 @@ const notificationBody = (comment: { id: number, content: string }, user: { name
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.NTFY_TOKEN}`
|
||||
},
|
||||
clear: true
|
||||
}
|
||||
},
|
||||
{
|
||||
action: 'http',
|
||||
label: 'Delete comment',
|
||||
url: `${process.env.NEXT_PUBLIC_SITE_URL}/api/comments/moderate/${comment.id}`,
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.NTFY_TOKEN}`
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -14,7 +14,28 @@ export async function PATCH(request: Request, {params}: { params: Promise<{ id:
|
||||
.update({published: true})
|
||||
.eq('id', id)
|
||||
|
||||
return new Response(JSON.stringify({}), {status: 200})
|
||||
return new Response(null, {status: 204})
|
||||
}
|
||||
return new Response(JSON.stringify({status: 'Not Found'}), {status: 404})
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({status: 'Unauthorized'}), {status: 401})
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request, {params}: { params: Promise<{ id: number }> }) {
|
||||
const {id} = await params
|
||||
const headersList = await headers()
|
||||
const authorizationHeader = headersList.get('authorization')
|
||||
|
||||
if (authorizationHeader === `Bearer ${process.env.NTFY_TOKEN}`) {
|
||||
if (typeof id !== 'undefined') {
|
||||
const supabase = await createClient()
|
||||
|
||||
await supabase.from('comments')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
|
||||
return new Response(null, {status: 204})
|
||||
}
|
||||
return new Response(JSON.stringify({status: 'Not Found'}), {status: 404})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user