@@ -390,103 +390,111 @@ export class AiWorkflowService {
390390 }
391391
392392 async getRunItems ( workflowId : string , runId : string , user : JwtUser ) {
393- const workflow = await this . prisma . aiWorkflow . findUnique ( {
394- where : { id : workflowId } ,
395- } ) ;
396- if ( ! workflow ) {
397- this . logger . error ( `Workflow with id ${ workflowId } not found.` ) ;
398- throw new NotFoundException ( `Workflow with id ${ workflowId } not found.` ) ;
399- }
400-
401- const run = await this . prisma . aiWorkflowRun . findUnique ( {
402- where : { id : runId } ,
403- include : { workflow : true } ,
404- } ) ;
405- if ( ! run || run . workflowId !== workflowId ) {
406- this . logger . error (
407- `Run with id ${ runId } not found or does not belong to workflow ${ workflowId } .` ,
408- ) ;
409- throw new NotFoundException (
410- `Run with id ${ runId } not found or does not belong to workflow ${ workflowId } .` ,
411- ) ;
412- }
393+ try {
394+ const workflow = await this . prisma . aiWorkflow . findUnique ( {
395+ where : { id : workflowId } ,
396+ } ) ;
397+ if ( ! workflow ) {
398+ this . logger . error ( `Workflow with id ${ workflowId } not found.` ) ;
399+ throw new NotFoundException (
400+ `Workflow with id ${ workflowId } not found.` ,
401+ ) ;
402+ }
413403
414- const submission = run . submissionId
415- ? await this . prisma . submission . findUnique ( {
416- where : { id : run . submissionId } ,
417- } )
418- : null ;
419- const challengeId = submission ?. challengeId ;
404+ const run = await this . prisma . aiWorkflowRun . findUnique ( {
405+ where : { id : runId } ,
406+ include : { workflow : true } ,
407+ } ) ;
408+ if ( ! run || run . workflowId !== workflowId ) {
409+ this . logger . error (
410+ `Run with id ${ runId } not found or does not belong to workflow ${ workflowId } .` ,
411+ ) ;
412+ throw new NotFoundException (
413+ `Run with id ${ runId } not found or does not belong to workflow ${ workflowId } .` ,
414+ ) ;
415+ }
420416
421- if ( ! challengeId ) {
422- this . logger . error (
423- `Challenge ID not found for submission ${ run . submissionId } ` ,
424- ) ;
425- throw new InternalServerErrorException (
426- `Challenge ID not found for submission ${ run . submissionId } ` ,
427- ) ;
428- }
417+ const submission = run . submissionId
418+ ? await this . prisma . submission . findUnique ( {
419+ where : { id : run . submissionId } ,
420+ } )
421+ : null ;
422+ const challengeId = submission ?. challengeId ;
429423
430- const challenge : ChallengeData =
431- await this . challengeApiService . getChallengeDetail ( challengeId ) ;
424+ if ( ! challengeId ) {
425+ this . logger . error (
426+ `Challenge ID not found for submission ${ run . submissionId } ` ,
427+ ) ;
428+ throw new InternalServerErrorException (
429+ `Challenge ID not found for submission ${ run . submissionId } ` ,
430+ ) ;
431+ }
432432
433- if ( ! challenge ) {
434- throw new InternalServerErrorException (
435- `Challenge with id ${ challengeId } was not found!` ,
436- ) ;
437- }
433+ const challenge : ChallengeData =
434+ await this . challengeApiService . getChallengeDetail ( challengeId ) ;
438435
439- const isM2mOrAdmin = user . isMachine || user . roles ?. includes ( UserRole . Admin ) ;
440- if ( ! isM2mOrAdmin ) {
441- const requiredRoles = [
442- UserRole . Reviewer ,
443- UserRole . ProjectManager ,
444- UserRole . Copilot ,
445- UserRole . Submitter ,
446- ] . map ( ( r ) => r . toLowerCase ( ) ) ;
436+ if ( ! challenge ) {
437+ throw new InternalServerErrorException (
438+ `Challenge with id ${ challengeId } was not found!` ,
439+ ) ;
440+ }
447441
448- const userRoles = await this . resourceApiService . getMemberResourcesRoles (
449- challengeId ,
450- user . userId ,
451- ) ;
442+ const isM2mOrAdmin =
443+ user . isMachine || user . roles ?. includes ( UserRole . Admin ) ;
444+ if ( ! isM2mOrAdmin ) {
445+ const requiredRoles = [
446+ UserRole . Reviewer ,
447+ UserRole . ProjectManager ,
448+ UserRole . Copilot ,
449+ UserRole . Submitter ,
450+ ] . map ( ( r ) => r . toLowerCase ( ) ) ;
451+
452+ const userRoles = await this . resourceApiService . getMemberResourcesRoles (
453+ challengeId ,
454+ user . userId ,
455+ ) ;
452456
453- this . logger . debug ( userRoles ) ;
454- const memberRoles = userRoles . filter ( ( resource ) =>
455- requiredRoles . some (
456- ( role ) =>
457- resource . roleName ! . toLowerCase ( ) . indexOf ( role . toLowerCase ( ) ) >= 0 ,
458- ) ,
459- ) ;
457+ this . logger . debug ( userRoles ) ;
458+ const memberRoles = userRoles . filter ( ( resource ) =>
459+ requiredRoles . some (
460+ ( role ) =>
461+ resource . roleName ! . toLowerCase ( ) . indexOf ( role . toLowerCase ( ) ) >= 0 ,
462+ ) ,
463+ ) ;
460464
461- if ( ! memberRoles . length ) {
462- throw new ForbiddenException ( 'Insufficient permissions' ) ;
463- }
465+ if ( ! memberRoles . length ) {
466+ throw new ForbiddenException ( 'Insufficient permissions' ) ;
467+ }
464468
465- if (
466- challenge . status !== ChallengeStatus . COMPLETED &&
467- memberRoles . some (
468- ( r ) => r . roleName ?. toLowerCase ( ) === UserRole . Submitter . toLowerCase ( ) ,
469- ) &&
470- user . userId !== submission ?. memberId
471- ) {
472- this . logger . log (
473- `Submitter ${ user . userId } trying to access AI workflow run for other submitters.` ,
474- ) ;
475- throw new ForbiddenException ( 'Insufficient permissions' ) ;
469+ if (
470+ challenge . status !== ChallengeStatus . COMPLETED &&
471+ memberRoles . some (
472+ ( r ) =>
473+ r . roleName ?. toLowerCase ( ) === UserRole . Submitter . toLowerCase ( ) ,
474+ ) &&
475+ user . userId !== submission ?. memberId
476+ ) {
477+ this . logger . log (
478+ `Submitter ${ user . userId } trying to access AI workflow run for other submitters.` ,
479+ ) ;
480+ throw new ForbiddenException ( 'Insufficient permissions' ) ;
481+ }
476482 }
477- }
478483
479- const items = await this . prisma . aiWorkflowRunItem . findMany ( {
480- where : { workflowRunId : runId } ,
481- include : {
482- comments : true ,
483- } ,
484- orderBy : {
485- createdAt : 'asc' ,
486- } ,
487- } ) ;
484+ const items = await this . prisma . aiWorkflowRunItem . findMany ( {
485+ where : { workflowRunId : runId } ,
486+ include : {
487+ comments : true ,
488+ } ,
489+ orderBy : {
490+ createdAt : 'asc' ,
491+ } ,
492+ } ) ;
488493
489- return items ;
494+ return items ;
495+ } catch ( e ) {
496+ this . logger . debug ( e , 'Error on getRunItems' ) ;
497+ }
490498 }
491499
492500 async updateRunItem (
0 commit comments