forked from JumboCode/TheLegacyProject
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tyler/caleb/drive #136
Merged
Merged
Tyler/caleb/drive #136
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -2,9 +2,7 @@ import { withSessionAndRole } from "@server/decorator"; | |
import { NextResponse } from "next/server"; | ||
import { seniorPostResponse, postSeniorSchema } from "./route.schema"; | ||
import { prisma } from "@server/db/client"; | ||
import { randomUUID } from "crypto"; | ||
import { google } from "googleapis"; | ||
import { env } from "process"; | ||
import { createDriveService } from "@server/service"; | ||
|
||
// @TODO - Use google drive service to create folder | ||
export const POST = withSessionAndRole( | ||
|
@@ -47,11 +45,36 @@ export const POST = withSessionAndRole( | |
}) | ||
); | ||
} | ||
const baseFolder = "1MVyWBeKCd1erNe9gkwBf7yz3wGa40g9a"; // TODO: make env variable | ||
|
||
const chapter = await prisma.chapter.findFirst({ | ||
where: { | ||
id: session.user.ChapterID, | ||
}, | ||
}); | ||
if (!chapter) { | ||
return NextResponse.json( | ||
seniorPostResponse.parse({ | ||
code: "UNKNOWN", | ||
message: "Chapter not found", | ||
}), | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
const senior = await prisma.senior.create({ | ||
data: { | ||
firstname: seniorBody.firstname, | ||
lastname: seniorBody.lastname, | ||
location: seniorBody.location, | ||
description: seniorBody.description, | ||
ChapterID: session.user.ChapterID, | ||
StudentIDs: seniorBody.StudentIDs, | ||
}, | ||
}); | ||
|
||
const baseFolder = chapter.chapterFolder; // TODO: make env variable | ||
const fileMetadata = { | ||
name: [ | ||
`${seniorBody.firstname}_${seniorBody.lastname}-${randomUUID()}`, | ||
], | ||
name: [`${seniorBody.firstname}_${seniorBody.lastname}_${senior.id}`], | ||
mimeType: "application/vnd.google-apps.folder", | ||
parents: [baseFolder], | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're changing the other route to use |
||
|
@@ -60,37 +83,18 @@ export const POST = withSessionAndRole( | |
fields: "id", | ||
}; | ||
|
||
const { access_token, refresh_token } = (await prisma.account.findFirst({ | ||
where: { | ||
userId: session.user.id, | ||
}, | ||
})) ?? { access_token: null }; | ||
const auth = new google.auth.OAuth2({ | ||
clientId: env.GOOGLE_CLIENT_ID, | ||
clientSecret: env.GOOGLE_CLIENT_SECRET, | ||
}); | ||
auth.setCredentials({ | ||
access_token, | ||
refresh_token, | ||
}); | ||
const service = google.drive({ | ||
version: "v3", | ||
auth, | ||
}); | ||
const service = await createDriveService(session.user.id); | ||
|
||
const file = await (service as NonNullable<typeof service>).files.create( | ||
fileCreateData | ||
); | ||
const googleFolderId = (file as any).data.id; | ||
|
||
const senior = await prisma.senior.create({ | ||
await prisma.senior.update({ | ||
where: { | ||
id: senior.id, | ||
}, | ||
data: { | ||
firstname: seniorBody.firstname, | ||
lastname: seniorBody.lastname, | ||
location: seniorBody.location, | ||
description: seniorBody.description, | ||
ChapterID: session.user.ChapterID, | ||
StudentIDs: seniorBody.StudentIDs, | ||
folder: googleFolderId, | ||
}, | ||
}); | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if it's necessary to include the new chapter ID as part of the folder name. We currently don't have any constraints that uni name is unique. What do you guys think?