Skip to content

Commit

Permalink
Protect Attendee Routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoder committed Oct 24, 2023
1 parent f503e61 commit 6b6f28e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
5 changes: 2 additions & 3 deletions pages/api/attendee/[slug]/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default async function handler(
}
}
});
if (!attendee)
if (!attendee){
return res.status(400).json({
error: "Attendee does not exist."
});

}
let project = await prisma.project.create({
data: {
name: req.body.name,
Expand All @@ -38,7 +38,6 @@ export default async function handler(
}
}
});
console.log(project);
return res.json({
project
});
Expand Down
24 changes: 21 additions & 3 deletions pages/api/attendee/[slug]/project/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ export default async function handler(
) {
try {
const slug = await getHackathonSlug(req.query.slug as string);
let project = await prisma.project.delete({
let attendee = await prisma.attendee.findFirst({
where: {
id: req.body.id
tokens: {
some: {
token: req.cookies[slug]
}
}
}
});
if (!attendee){
return res.status(400).json({
error: "Attendee does not exist."
});
}
await prisma.project.deleteMany({
where: {
id: req.body.id,
collaborators: {
some: {
id: attendee.id
}
}
}
});
console.log(project);
return res.json({
deleted: true
});
Expand Down
18 changes: 18 additions & 0 deletions pages/api/attendee/[slug]/project/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ export default async function handler(
let slug = req.query.slug as string;

slug = await getHackathonSlug(slug);

let attendee = await prisma.attendee.findFirst({
where: {
tokens: {
some: {
token: req.cookies[slug]
}
},
project: {
id
}
}
});
if (!attendee){
return res.status(400).json({
error: "Attendee does not exist or is not a member of this project."
});
}

let project = await prisma.project.update({
where: {
Expand Down
13 changes: 0 additions & 13 deletions pages/api/hello.ts

This file was deleted.

0 comments on commit 6b6f28e

Please sign in to comment.