-
Notifications
You must be signed in to change notification settings - Fork 9
#3389 create update submissions #3398
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
Changes from 7 commits
9cd0af8
b069f16
3a6aebf
01a83a3
18198a9
3717612
246d9fb
c975511
ec1dd45
ebf911b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,21 +19,24 @@ import { | |
| DeletedException, | ||
| HttpException, | ||
| NotFoundException, | ||
| AccessDeniedGuestException | ||
| AccessDeniedGuestException, | ||
| InvalidOrganizationException | ||
| } from '../utils/errors.utils'; | ||
| import prisma from '../prisma/prisma'; | ||
| import { getFaqQueryArgs } from '../prisma-query-args/faq.query-args'; | ||
| import { | ||
| getPartQueryArgs, | ||
| getPartReviewQueryArgs, | ||
| getPartReviewRequestQueryArgs | ||
| getPartReviewRequestQueryArgs, | ||
| getPartSubmissionQueryArgs | ||
| } from '../prisma-query-args/part-review.query-args'; | ||
| import { faqTransformer } from '../transformers/faq.transformer'; | ||
| import { | ||
| partReviewRequestTransformer, | ||
| partsReviewCommonMistakeTransformer, | ||
| partTransformer, | ||
| partPreviewTransformer | ||
| partPreviewTransformer, | ||
| partSubmissionTransformer | ||
| } from '../transformers/part-review.transformer'; | ||
| import { isUserPartOfTeams } from '../utils/teams.utils'; | ||
| import { uploadFile } from '../utils/google-integration.utils'; | ||
|
|
@@ -238,6 +241,118 @@ export default class PartReviewService { | |
| return partTransformer(deletedPart); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a submission for a given part | ||
| * @param partId the part that the submission will be added to | ||
| * @param creator the creator | ||
| * @param organizationId the organization | ||
| * @param name the name of the submission | ||
| * @param notes optional notes | ||
| * @returns the created submission | ||
| */ | ||
| static async createSubmission(partId: string, creator: User, organizationId: string, name: string, notes?: string) { | ||
| const part = await prisma.part.findUnique({ | ||
| where: { partId }, | ||
| include: { project: { include: { wbsElement: true } } } | ||
|
Member
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. Can we use queryargs for this |
||
| }); | ||
| if (!part) throw new NotFoundException('Part', partId); | ||
| if (part.dateDeleted) throw new DeletedException('Part', partId); | ||
| if (part.project.wbsElement.organizationId !== organizationId) throw new InvalidOrganizationException('Part'); | ||
|
|
||
| const submission = await prisma.partSubmission.create({ | ||
| data: { | ||
| name, | ||
| notes, | ||
| part: { | ||
| connect: { partId } | ||
| }, | ||
| userCreated: { | ||
| connect: { userId: creator.userId } | ||
| } | ||
| }, | ||
| ...getPartSubmissionQueryArgs(organizationId) | ||
| }); | ||
|
|
||
| return partSubmissionTransformer(submission); | ||
| } | ||
|
|
||
| /** | ||
| * updates a given submission | ||
| * @param submissionId the submission being updated | ||
| * @param updater the user updating (must be the creator) | ||
| * @param organizationId the organization | ||
| * @param name the new name of the submission | ||
| * @param notes the new notes (optional) | ||
| * @returns the updated submission | ||
| */ | ||
| static async updateSubmission(submissionId: string, updater: User, organizationId: string, name: string, notes?: string) { | ||
| const submission = await prisma.partSubmission.findUnique({ | ||
| where: { partSubmissionId: submissionId }, | ||
| include: { part: { include: { project: { include: { wbsElement: true } } } } } | ||
|
Member
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. Same here |
||
| }); | ||
| if (!submission) throw new NotFoundException('Part Submission', submissionId); | ||
| if (submission.dateDeleted) throw new DeletedException('Part Submission', submissionId); | ||
| if (submission.part.project.wbsElement.organizationId !== organizationId) | ||
| throw new InvalidOrganizationException('Part Submission'); | ||
|
|
||
| if (updater.userId !== submission.userCreatedId) | ||
| throw new AccessDeniedException('only submission creators can update submissions'); | ||
|
|
||
| const updatedSubmission = await prisma.partSubmission.update({ | ||
| where: { partSubmissionId: submissionId }, | ||
| data: { | ||
| name, | ||
| notes: notes ?? submission.notes | ||
| }, | ||
| ...getPartSubmissionQueryArgs(organizationId) | ||
| }); | ||
|
|
||
| return partSubmissionTransformer(updatedSubmission); | ||
| } | ||
|
|
||
| /** | ||
| * Uploads an array of files to a given submission | ||
| * @param submissionId the submission | ||
| * @param uploader the user uploading (must be creator) | ||
| * @param organizationId the organization | ||
| * @param files an array of files to upload | ||
| * @returns the updated submission | ||
| */ | ||
| static async uploadSubmissionFiles( | ||
| submissionId: string, | ||
| uploader: User, | ||
| organizationId: string, | ||
| files: Express.Multer.File[] | ||
| ) { | ||
| const submission = await prisma.partSubmission.findUnique({ | ||
| where: { partSubmissionId: submissionId }, | ||
| include: { part: { include: { project: { include: { wbsElement: true } } } } } | ||
|
Member
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. Same here |
||
| }); | ||
| if (!submission) throw new NotFoundException('Part Submission', submissionId); | ||
| if (submission.dateDeleted) throw new DeletedException('Part Submission', submissionId); | ||
| if (submission.part.project.wbsElement.organizationId !== organizationId) | ||
| throw new InvalidOrganizationException('Part Submission'); | ||
|
|
||
| if (uploader.userId !== submission.userCreatedId) | ||
| throw new AccessDeniedException('only submission creators can update submissions'); | ||
|
|
||
| const fileIds = await Promise.all( | ||
| files.map(async (file) => { | ||
| return (await uploadFile(file)).id; | ||
| }) | ||
| ); | ||
|
|
||
| const updatedSubmission = await prisma.partSubmission.update({ | ||
| where: { partSubmissionId: submissionId }, | ||
| data: { | ||
| fileIds | ||
| }, | ||
| ...getPartSubmissionQueryArgs(organizationId) | ||
| }); | ||
|
|
||
| return partSubmissionTransformer(updatedSubmission); | ||
| } | ||
|
|
||
| /** | ||
| * Uses the given organizationID to and returns an array of part tags | ||
| * @param organizationId the organization to get the parts for | ||
|
|
||
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.
Same comment here as on the last PR