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

@@ -602,4 +602,25 @@ export class CredentialsService {
mergedCredentials.data = decryptedData;
}
}
/**
* Create a new credential in user's account and return it along the scopes
* If a projectId is send, then it also binds the credential to that specific project
*/
async createCredential(credentialsData: CredentialRequest.CredentialProperties, user: User) {
const newCredential = await this.prepareCreateData(credentialsData);
const encryptedData = this.createEncryptedData(null, newCredential);
const { shared, ...credential } = await this.save(
newCredential,
encryptedData,
user,
credentialsData.projectId,
);
const scopes = await this.getCredentialScopes(user, credential.id);
return { ...credential, scopes };
}
}