refactor(core): Encapsulate logic to create new credential into its own method (#12361)

This commit is contained in:
Ricardo Espinoza
2024-12-27 08:26:36 -05:00
committed by GitHub
parent 6891cefa6d
commit 66f8c9e249
6 changed files with 258 additions and 15 deletions

View File

@@ -147,32 +147,22 @@ export class CredentialsController {
@Post('/')
async createCredentials(req: CredentialRequest.Create) {
const newCredential = await this.credentialsService.prepareCreateData(req.body);
const encryptedData = this.credentialsService.createEncryptedData(null, newCredential);
const { shared, ...credential } = await this.credentialsService.save(
newCredential,
encryptedData,
req.user,
req.body.projectId,
);
const newCredential = await this.credentialsService.createCredential(req.body, req.user);
const project = await this.sharedCredentialsRepository.findCredentialOwningProject(
credential.id,
newCredential.id,
);
this.eventService.emit('credentials-created', {
user: req.user,
credentialType: credential.type,
credentialId: credential.id,
credentialType: newCredential.type,
credentialId: newCredential.id,
publicApi: false,
projectId: project?.id,
projectType: project?.type,
});
const scopes = await this.credentialsService.getCredentialScopes(req.user, credential.id);
return { ...credential, scopes };
return newCredential;
}
@Patch('/:credentialId')