@@ -496,7 +496,6 @@ export class AiWorkflowService {
496496 runId : string ,
497497 itemId : string ,
498498 patchData : UpdateAiWorkflowRunItemDto ,
499- user : JwtUser ,
500499 ) {
501500 const workflow = await this . prisma . aiWorkflow . findUnique ( {
502501 where : { id : workflowId } ,
@@ -545,71 +544,12 @@ export class AiWorkflowService {
545544 updateData . questionScore = patchData . questionScore ;
546545 }
547546
548- return this . prisma . $transaction ( async ( tx ) => {
549- await tx . aiWorkflowRunItem . update ( {
550- where : { id : itemId } ,
551- include : {
552- comments : true ,
553- } ,
554- data : updateData ,
555- } ) ;
556-
557- if ( patchData . comments ) {
558- for ( const comment of patchData . comments ) {
559- if ( comment . id ) {
560- const existingComment =
561- await tx . aiWorkflowRunItemComment . findUnique ( {
562- where : { id : comment . id } ,
563- } ) ;
564- if ( ! existingComment ) {
565- this . logger . error ( `Comment with id ${ comment . id } not found.` ) ;
566- throw new NotFoundException (
567- `Comment with id ${ comment . id } not found.` ,
568- ) ;
569- }
570-
571- if (
572- existingComment . createdBy !== user . userId &&
573- ! user . roles ?. includes ( UserRole . Admin )
574- ) {
575- this . logger . error (
576- `User ${ user . userId } unauthorized to update comment ${ comment . id } .` ,
577- ) ;
578- throw new ForbiddenException (
579- `Unauthorized to update comment ${ comment . id } .` ,
580- ) ;
581- }
582-
583- await tx . aiWorkflowRunItemComment . update ( {
584- where : { id : comment . id } ,
585- data : {
586- content : comment . content ,
587- updatedAt : new Date ( ) ,
588- } ,
589- } ) ;
590- } else {
591- await tx . aiWorkflowRunItemComment . create ( {
592- data : {
593- workflowRunItemId : itemId ,
594- content : comment . content ,
595- parentId : comment . parentId ,
596- createdBy : '' ,
597- createdAt : new Date ( ) ,
598- userId : user . userId as string ,
599- updatedAt : new Date ( ) ,
600- updatedBy : '' ,
601- } ,
602- } ) ;
603- }
604- }
605- }
606-
607- return tx . aiWorkflowRunItem . findUnique ( {
608- where : { id : itemId } ,
609- include : {
610- comments : true ,
611- } ,
612- } ) ;
547+ return this . prisma . aiWorkflowRunItem . update ( {
548+ where : { id : itemId } ,
549+ include : {
550+ comments : true ,
551+ } ,
552+ data : updateData ,
613553 } ) ;
614554 }
615555}
0 commit comments