diff --git a/apps/api/v2/src/modules/organizations/delegation-credentials/services/organizations-delegation-credential.service.ts b/apps/api/v2/src/modules/organizations/delegation-credentials/services/organizations-delegation-credential.service.ts index 1f39ef937d..b42d63e0f9 100644 --- a/apps/api/v2/src/modules/organizations/delegation-credentials/services/organizations-delegation-credential.service.ts +++ b/apps/api/v2/src/modules/organizations/delegation-credentials/services/organizations-delegation-credential.service.ts @@ -38,6 +38,15 @@ export class OrganizationsDelegationCredentialService { delegatedServiceAccountUser: User, body: UpdateDelegationCredentialInput ) { + const delegationCredential = + await this.organizationsDelegationCredentialRepository.findByIdWithWorkspacePlatform( + delegationCredentialId + ); + + if (!delegationCredential) { + throw new NotFoundException(`DelegationCredential with id ${delegationCredentialId} not found`); + } + if (body.enabled !== undefined) { await this.updateDelegationCredentialEnabled( orgId, @@ -49,15 +58,8 @@ export class OrganizationsDelegationCredentialService { if (body.serviceAccountKey !== undefined) { await this.updateDelegationCredentialServiceAccountKey(delegationCredentialId, body.serviceAccountKey); } - const delegationCredential = - await this.organizationsDelegationCredentialRepository.findByIdWithWorkspacePlatform( - delegationCredentialId - ); - if (!delegationCredential) { - throw new NotFoundException(`DelegationCredential with id ${delegationCredentialId} not found`); - } - return delegationCredential; + return { ...delegationCredential, enabled: body?.enabled ?? delegationCredential?.enabled }; } async updateDelegationCredentialEnabled(