forked from JumboCode/TheLegacyProject
-
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.
delete permissions upon deleting chapter
- Loading branch information
1 parent
2533716
commit cd1a396
Showing
5 changed files
with
58 additions
and
15 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,35 @@ | ||
import { NextResponse } from "next/server"; | ||
import { withSessionAndRole } from "@server/decorator"; | ||
import { prisma } from "@server/db/client"; | ||
import { driveV3 } from "@server/service"; | ||
|
||
export const DELETE = withSessionAndRole(["ADMIN"], async ({ params }) => { | ||
// TODO | ||
// 1. Implement route.client.ts | ||
// 2. Implement route.schema.ts | ||
// 3. Finish deleting chapter | ||
// 4. Add it to AdminHomePage | ||
|
||
const chapterId = params.params.chapterId; | ||
const chapter = await prisma.chapter.findUnique({ | ||
where: { | ||
id: chapterId, | ||
}, | ||
}); | ||
|
||
if (chapter == null) { | ||
// If no ID is found, chapter has been deleted by another admin. | ||
return NextResponse.json("ok"); | ||
} | ||
|
||
await Promise.allSettled( | ||
chapter.permissions.map((permissionId) => | ||
driveV3.permissions.delete({ | ||
fileId: chapter.chapterFolder, | ||
permissionId: permissionId, | ||
}) | ||
) | ||
); | ||
|
||
return NextResponse.json("ok"); | ||
}); |
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