-
Notifications
You must be signed in to change notification settings - Fork 9
feat(PM-1792): update workflow run item #91
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 14 commits
dc80999
d224404
56e99a3
a207c7e
8251d86
237d5d6
997a68a
abf0b9a
ab1a860
0a02608
88a8e1d
a2a73bd
7334871
f9b79f4
08c1a0e
afe7b6f
65837e4
72af621
01e2bbc
3bdd63c
7efc25f
cdf35b1
749617f
25369e4
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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |
| CreateAiWorkflowRunDto, | ||
| UpdateAiWorkflowDto, | ||
| UpdateAiWorkflowRunDto, | ||
| UpdateAiWorkflowRunItemDto, | ||
| } from '../../dto/aiWorkflow.dto'; | ||
| import { ScorecardStatus } from 'src/dto/scorecard.dto'; | ||
| import { JwtUser } from 'src/shared/modules/global/jwt.service'; | ||
|
|
@@ -444,12 +445,15 @@ export class AiWorkflowService { | |
| UserRole.Submitter, | ||
| ].map((r) => r.toLowerCase()); | ||
|
|
||
| const memberRoles = ( | ||
| await this.resourceApiService.getMemberResourcesRoles( | ||
| challengeId, | ||
| user.userId, | ||
| ) | ||
| ).filter((resource) => | ||
| const userRoles = await this.resourceApiService.getMemberResourcesRoles( | ||
| challengeId, | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| user.userId, | ||
| ); | ||
|
|
||
| this.logger.debug(userRoles); | ||
| this.logger.debug(user); | ||
hentrymartin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.logger.debug(submission); | ||
| const memberRoles = userRoles.filter((resource) => | ||
| requiredRoles.some( | ||
| (role) => | ||
| resource.roleName!.toLowerCase().indexOf(role.toLowerCase()) >= 0, | ||
|
|
@@ -465,7 +469,7 @@ export class AiWorkflowService { | |
| memberRoles.some( | ||
| (r) => r.roleName?.toLowerCase() === UserRole.Submitter.toLowerCase(), | ||
| ) && | ||
| user.userId !== submission?.memberId | ||
| user.userId?.toString() !== submission?.memberId | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| this.logger.log( | ||
| `Submitter ${user.userId} trying to access AI workflow run for other submitters.`, | ||
|
|
@@ -486,4 +490,126 @@ export class AiWorkflowService { | |
|
|
||
| return items; | ||
| } | ||
|
|
||
| async updateRunItem( | ||
| workflowId: string, | ||
| runId: string, | ||
| itemId: string, | ||
| patchData: UpdateAiWorkflowRunItemDto, | ||
| user: JwtUser, | ||
| ) { | ||
| const workflow = await this.prisma.aiWorkflow.findUnique({ | ||
| where: { id: workflowId }, | ||
| }); | ||
| if (!workflow) { | ||
| this.logger.error(`Workflow with id ${workflowId} not found.`); | ||
| throw new NotFoundException(`Workflow with id ${workflowId} not found.`); | ||
| } | ||
|
|
||
| const run = await this.prisma.aiWorkflowRun.findUnique({ | ||
| where: { id: runId }, | ||
| }); | ||
| if (!run || run.workflowId !== workflowId) { | ||
| this.logger.error( | ||
| `Run with id ${runId} not found or does not belong to workflow ${workflowId}.`, | ||
| ); | ||
| throw new NotFoundException( | ||
| `Run with id ${runId} not found or does not belong to workflow ${workflowId}.`, | ||
| ); | ||
| } | ||
|
|
||
| const runItem = await this.prisma.aiWorkflowRunItem.findUnique({ | ||
| where: { id: itemId }, | ||
| }); | ||
| if (!runItem || runItem.workflowRunId !== runId) { | ||
| this.logger.error( | ||
| `Run item with id ${itemId} not found or does not belong to run ${runId}.`, | ||
| ); | ||
| throw new NotFoundException( | ||
| `Run item with id ${itemId} not found or does not belong to run ${runId}.`, | ||
| ); | ||
| } | ||
|
|
||
| const updateData: any = {}; | ||
|
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. Consider using a more specific type for |
||
|
|
||
| if (patchData.content !== undefined) { | ||
| updateData.content = patchData.content; | ||
| } | ||
| if (patchData.upVotes !== undefined) { | ||
|
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. We should extend the logic here to allow M2M to be able to update everything, except 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. @kkartunov Now this logic is updated, can you please do a review again? |
||
| updateData.upVotes = patchData.upVotes; | ||
| } | ||
| if (patchData.downVotes !== undefined) { | ||
| updateData.downVotes = patchData.downVotes; | ||
| } | ||
| if (patchData.questionScore !== undefined) { | ||
| updateData.questionScore = patchData.questionScore; | ||
| } | ||
|
|
||
| return this.prisma.$transaction(async (tx) => { | ||
| await tx.aiWorkflowRunItem.update({ | ||
| where: { id: itemId }, | ||
| include: { | ||
hentrymartin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| comments: true, | ||
| }, | ||
| data: updateData, | ||
| }); | ||
|
|
||
| if (patchData.comments) { | ||
| for (const comment of patchData.comments) { | ||
| if (comment.id) { | ||
| const existingComment = | ||
| await tx.aiWorkflowRunItemComment.findUnique({ | ||
| where: { id: comment.id }, | ||
| }); | ||
| if (!existingComment) { | ||
| this.logger.error(`Comment with id ${comment.id} not found.`); | ||
| throw new NotFoundException( | ||
| `Comment with id ${comment.id} not found.`, | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| existingComment.createdBy !== user.userId && | ||
| !user.roles?.includes(UserRole.Admin) | ||
| ) { | ||
| this.logger.error( | ||
| `User ${user.userId} unauthorized to update comment ${comment.id}.`, | ||
| ); | ||
| throw new ForbiddenException( | ||
| `Unauthorized to update comment ${comment.id}.`, | ||
| ); | ||
| } | ||
|
|
||
| await tx.aiWorkflowRunItemComment.update({ | ||
| where: { id: comment.id }, | ||
| data: { | ||
| content: comment.content, | ||
| updatedAt: new Date(), | ||
| }, | ||
| }); | ||
| } else { | ||
| await tx.aiWorkflowRunItemComment.create({ | ||
| data: { | ||
| workflowRunItemId: itemId, | ||
| content: comment.content, | ||
| parentId: comment.parentId, | ||
| createdBy: '', | ||
|
||
| createdAt: new Date(), | ||
| userId: user.userId as string, | ||
| updatedAt: new Date(), | ||
| updatedBy: '', | ||
|
||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return tx.aiWorkflowRunItem.findUnique({ | ||
hentrymartin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| where: { id: itemId }, | ||
| include: { | ||
| comments: true, | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.