Skip to content

Commit

Permalink
delete user and chapter request when accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-j-edwards committed Apr 11, 2024
1 parent 820221b commit 3f8d1eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/app/api/handle-chapter-request/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ export const POST = withSession(async ({ req, session }) => {
location: chapterRequest.universityAddress,
},
});
await prisma.chapterRequest.update({
await prisma.chapterRequest.delete({
where: {
id: body.chapterRequestId,
},
data: {
approved: "APPROVED",
},
});

const baseFolder = env.GOOGLE_BASEFOLDER; // TODO: make env variable
Expand Down
10 changes: 6 additions & 4 deletions src/app/api/user-request/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const DELETE = withSession(async ({ req, session }) => {

export const PATCH = withSession(async ({ req, session }) => {
try {
console.log("1");
const approveChapterReq = ManageChapterRequest.safeParse(await req.json());
if (!approveChapterReq.success) {
return NextResponse.json(
Expand All @@ -168,12 +169,14 @@ export const PATCH = withSession(async ({ req, session }) => {
);
}
const targetUID = approveChapterReq.data.userId;
console.log(targetUID);
const target = await prisma.user.findFirst({
where: {
id: targetUID,
},
});
if (target == null) {
console.log("2");
return NextResponse.json(
ManageChapterRequestResponse.parse({
code: "INVALID_REQUEST",
Expand All @@ -188,6 +191,7 @@ export const PATCH = withSession(async ({ req, session }) => {
},
});
if (approveChapterRequest == null) {
console.log("3");
return NextResponse.json(
ManageChapterRequestResponse.parse({
code: "INVALID_REQUEST",
Expand All @@ -200,6 +204,7 @@ export const PATCH = withSession(async ({ req, session }) => {
session.user.role === "ADMIN" ||
(session.user.role === "CHAPTER_LEADER" &&
session.user.ChapterID === approveChapterRequest.chapterId);
console.log(canApprove);
if (!canApprove) {
return NextResponse.json(
ManageChapterRequestResponse.parse({
Expand All @@ -209,13 +214,10 @@ export const PATCH = withSession(async ({ req, session }) => {
{ status: 400 }
);
}
await prisma.userRequest.update({
await prisma.userRequest.delete({
where: {
uid: targetUID,
},
data: {
approved: "APPROVED",
},
});
const user = await prisma.user.update({
where: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DisplayChapterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const DisplayChapterInfo = ({
<PendingCard
key={user.id}
name={fullName(user.user)}
uid={user.id}
uid={user.uid}
/>
);
})}
Expand Down

0 comments on commit 3f8d1eb

Please sign in to comment.