-
Notifications
You must be signed in to change notification settings - Fork 3
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 #104 from TheLab-ms/feature/detail-page
- Loading branch information
Showing
10 changed files
with
257 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20230725020745_rsvp_constraints/migration.sql
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 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[eventId,accountId]` on the table `RSVP` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- CreateIndex | ||
CREATE UNIQUE INDEX "RSVP_eventId_accountId_key" ON "RSVP"("eventId", "accountId"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { getServerSession } from 'next-auth'; | ||
import { authOptions } from '../auth/[...nextauth]'; | ||
import { prisma } from '@/helpers/db'; | ||
import { CreateRSVPSchema } from '@/schemas/api/createRSVP'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (!req.method || (req.method !== 'POST' && req.method !== 'DELETE')) { | ||
res.status(405).json({ message: 'Method not allowed' }); | ||
return; | ||
} | ||
|
||
const session = await getServerSession(req, res, authOptions); | ||
if (!session) { | ||
res.status(401).json({ message: 'Unauthorized' }); | ||
return; | ||
} | ||
let rsvpData = null; | ||
try { | ||
rsvpData = CreateRSVPSchema.parse(JSON.parse(req.body)); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(400).json({ | ||
message: 'The data sent is not JSON', | ||
}); | ||
return; | ||
} | ||
const { eventId, operation } = rsvpData; | ||
|
||
const event = await prisma.event.findUnique({ | ||
where: { | ||
id: eventId, | ||
}, | ||
}); | ||
|
||
if (!event) { | ||
res.status(404).json({ message: 'Event not found' }); | ||
return; | ||
} | ||
console.log( | ||
`Attempting to ${operation} RSVP for event ${eventId} for user ${session.user.id}` | ||
); | ||
if (operation === 'create') { | ||
const rsvp = await prisma.rSVP.create({ | ||
data: { | ||
eventId: rsvpData.eventId, | ||
accountId: session.user.id, | ||
}, | ||
}); | ||
res.status(200).send(true); | ||
return; | ||
} | ||
|
||
if (operation === 'remove') { | ||
const rsvp = await prisma.rSVP.delete({ | ||
where: { | ||
eventId_accountId: { | ||
eventId: eventId, | ||
accountId: session.user.id, | ||
}, | ||
}, | ||
}); | ||
res.status(200).send(true); | ||
return; | ||
} | ||
} |
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
Oops, something went wrong.
0ec8eb7
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:
calendar – ./
calendar-psi-beige.vercel.app
calendar.thelabms.dev
calendar-git-main-thelab-ms.vercel.app
calendar-thelab-ms.vercel.app