-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from SuperViz/develop
Develop
- Loading branch information
Showing
10 changed files
with
105 additions
and
42 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.NEWSLETTER, | ||
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' | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters