-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(account): ✨ Add coupon code input
- Loading branch information
1 parent
9c20ef0
commit b345131
Showing
5 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Prisma, User } from 'db' | ||
import prisma from 'libs/prisma' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getSession } from 'next-auth/react' | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
if (req.method === 'POST') { | ||
const session = await getSession({ req }) | ||
|
||
if (!session?.user) | ||
return res.status(401).json({ message: 'Not authenticated' }) | ||
|
||
const user = session.user as User | ||
const { code } = JSON.parse(req.body) | ||
const coupon = await prisma.coupon.findFirst({ | ||
where: { code, dateRedeemed: null }, | ||
}) | ||
if (!coupon) return res.status(404).send({ message: 'Coupon not found' }) | ||
await prisma.user.update({ | ||
where: { id: user.id }, | ||
data: coupon.userPropertiesToUpdate as Prisma.UserUncheckedUpdateInput, | ||
}) | ||
await prisma.coupon.update({ | ||
where: { code }, | ||
data: { dateRedeemed: new Date() }, | ||
}) | ||
return res.send({ message: 'Coupon redeemed 🎊' }) | ||
} | ||
} | ||
|
||
export default handler |
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,8 @@ | ||
import { sendRequest } from 'utils' | ||
|
||
export const redeemCoupon = async (code: string) => | ||
sendRequest<{ message: string }>({ | ||
method: 'POST', | ||
url: '/api/coupons/redeem', | ||
body: { code }, | ||
}) |
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
b345131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
landing-page-v2 – ./apps/landing-page
landing-page-v2-git-main-typebot-io.vercel.app
landing-page-v2-typebot-io.vercel.app
landing-page-v2-jade.vercel.app
b345131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viewer-v2 – ./apps/viewer
viewer-v2-typebot-io.vercel.app
viewer-v2-git-main-typebot-io.vercel.app
typebot-viewer.vercel.app
b345131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder-v2 – ./apps/builder
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
next.typebot.io