mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-26 01:40:31 +01:00
Import drizzle replacing prisma
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
34
server/api/suggestion.post.ts
Normal file
34
server/api/suggestion.post.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
const SuggestionValidator = z.object({
|
||||
content: z.string()
|
||||
}).parse
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { content } = await readValidatedBody(event, SuggestionValidator)
|
||||
const { user } = await requireUserSession(event)
|
||||
const config = useRuntimeConfig(event)
|
||||
|
||||
await sendDiscordWebhookMessage(config, {
|
||||
title: 'New suggestion ✨',
|
||||
description: `**${user.username}** has requested **${content}** for the talents page.`,
|
||||
color: 15237114
|
||||
})
|
||||
|
||||
return useDB().insert(tables.suggestions)
|
||||
.values({
|
||||
email: user.email,
|
||||
content
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: tables.suggestions.email,
|
||||
set: {
|
||||
content
|
||||
},
|
||||
setWhere: sql`${tables.suggestions.email}
|
||||
=
|
||||
${user.email}`
|
||||
}).returning({
|
||||
content: tables.suggestions.content
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user