Skip to content

Commit

Permalink
Merge pull request #4 from SuperViz/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
carlossantos74 authored Aug 23, 2024
2 parents f4e8f54 + 4a49bd1 commit 638b9a4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app/api/webhooks/discord/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NextRequest, NextResponse } from "next/server";


export async function POST(request: NextRequest): Promise<NextResponse> {
const body = await request.text()
const parsed = JSON.parse(body)

console.log(parsed)

return NextResponse.json({}, { status: 200})
}
56 changes: 56 additions & 0 deletions src/app/api/webhooks/hackathon/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { NextRequest, NextResponse } from "next/server";
import { db } from '@/lib/prisma'
import { ActivationType } from "@/global/global.types";

export async function POST(request: NextRequest): Promise<NextResponse> {
try {
const body = await request.text()
const parsed = JSON.parse(body)

const field = parsed.form_response.definition.fields.find((field: any) => field.type === 'email')
const anwser = parsed.form_response.answers.find((anwser: any) => anwser.field.ref === field.ref)

if(!anwser.email) {
return NextResponse.json({}, { status: 400 })
}

const user = await db.user.findFirst({
where: {
email: anwser.email
}
})

if(!user) {
return NextResponse.json({message: 'User Doesn\'t exists '}, { status: 404 })
}

const activation = await db.activation.findFirst({
where: {
name: ActivationType.HACKATHON,
userId: user.id
}
})

if(!activation) {
return NextResponse.json({message: 'Activation Doesn\'t exists '}, { status: 404 })
}

await db.activation.update({
data: {
completed: true
},
where: {
id: activation.id
}
})

return NextResponse.json({ message: 'Success' }, { status: 200 })
} catch (error) {
console.log(error)

return NextResponse.json({}, {
status: 500,
statusText: 'Internal Server Error'
})
}
}

0 comments on commit 638b9a4

Please sign in to comment.