From e7ed6027d2aa9be7f64d5968c4338e63e56657fb Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Tue, 31 Aug 2021 10:36:23 +0200 Subject: [PATCH] feat: add delete methods to services and modules (#447) Signed-off-by: Timo Glastra --- .../core/src/modules/connections/ConnectionsModule.ts | 9 +++++++++ .../modules/connections/services/ConnectionService.ts | 10 ++++++++++ .../core/src/modules/credentials/CredentialsModule.ts | 9 +++++++++ .../modules/credentials/services/CredentialService.ts | 10 ++++++++++ packages/core/src/modules/proofs/ProofsModule.ts | 9 +++++++++ .../core/src/modules/proofs/services/ProofService.ts | 10 ++++++++++ 6 files changed, 57 insertions(+) diff --git a/packages/core/src/modules/connections/ConnectionsModule.ts b/packages/core/src/modules/connections/ConnectionsModule.ts index 408d58270c..3a1d507f79 100644 --- a/packages/core/src/modules/connections/ConnectionsModule.ts +++ b/packages/core/src/modules/connections/ConnectionsModule.ts @@ -199,6 +199,15 @@ export class ConnectionsModule { return this.connectionService.findById(connectionId) } + /** + * Delete a connection record by id + * + * @param connectionId the connection record id + */ + public async deleteById(connectionId: string) { + return this.connectionService.deleteById(connectionId) + } + /** * Find connection by verkey. * diff --git a/packages/core/src/modules/connections/services/ConnectionService.ts b/packages/core/src/modules/connections/services/ConnectionService.ts index b33157bab6..233e8a3599 100644 --- a/packages/core/src/modules/connections/services/ConnectionService.ts +++ b/packages/core/src/modules/connections/services/ConnectionService.ts @@ -464,6 +464,16 @@ export class ConnectionService { return this.connectionRepository.findById(connectionId) } + /** + * Delete a connection record by id + * + * @param connectionId the connection record id + */ + public async deleteById(connectionId: string) { + const connectionRecord = await this.getById(connectionId) + return this.connectionRepository.delete(connectionRecord) + } + /** * Find connection by verkey. * diff --git a/packages/core/src/modules/credentials/CredentialsModule.ts b/packages/core/src/modules/credentials/CredentialsModule.ts index 0e31411bf3..5e1fab906e 100644 --- a/packages/core/src/modules/credentials/CredentialsModule.ts +++ b/packages/core/src/modules/credentials/CredentialsModule.ts @@ -472,6 +472,15 @@ export class CredentialsModule { return this.credentialService.findById(connectionId) } + /** + * Delete a credential record by id + * + * @param credentialId the credential record id + */ + public async deleteById(credentialId: string) { + return this.credentialService.deleteById(credentialId) + } + private registerHandlers(dispatcher: Dispatcher) { dispatcher.registerHandler( new ProposeCredentialHandler(this.credentialService, this.agentConfig, this.credentialResponseCoordinator) diff --git a/packages/core/src/modules/credentials/services/CredentialService.ts b/packages/core/src/modules/credentials/services/CredentialService.ts index 736515bb7f..42d63d5cd9 100644 --- a/packages/core/src/modules/credentials/services/CredentialService.ts +++ b/packages/core/src/modules/credentials/services/CredentialService.ts @@ -723,6 +723,16 @@ export class CredentialService { return this.credentialRepository.findById(connectionId) } + /** + * Delete a credential record by id + * + * @param credentialId the credential record id + */ + public async deleteById(credentialId: string) { + const credentialRecord = await this.getById(credentialId) + return this.credentialRepository.delete(credentialRecord) + } + /** * Retrieve a credential record by connection id and thread id * diff --git a/packages/core/src/modules/proofs/ProofsModule.ts b/packages/core/src/modules/proofs/ProofsModule.ts index d93f482b0f..4bace42a4a 100644 --- a/packages/core/src/modules/proofs/ProofsModule.ts +++ b/packages/core/src/modules/proofs/ProofsModule.ts @@ -374,6 +374,15 @@ export class ProofsModule { return this.proofService.findById(proofRecordId) } + /** + * Delete a proof record by id + * + * @param proofId the proof record id + */ + public async deleteById(proofId: string) { + return this.proofService.deleteById(proofId) + } + private registerHandlers(dispatcher: Dispatcher) { dispatcher.registerHandler( new ProposePresentationHandler(this.proofService, this.agentConfig, this.proofResponseCoordinator) diff --git a/packages/core/src/modules/proofs/services/ProofService.ts b/packages/core/src/modules/proofs/services/ProofService.ts index 094ffd81dc..89bc37d6c5 100644 --- a/packages/core/src/modules/proofs/services/ProofService.ts +++ b/packages/core/src/modules/proofs/services/ProofService.ts @@ -867,6 +867,16 @@ export class ProofService { return this.proofRepository.findById(proofRecordId) } + /** + * Delete a proof record by id + * + * @param proofId the proof record id + */ + public async deleteById(proofId: string) { + const proofRecord = await this.getById(proofId) + return this.proofRepository.delete(proofRecord) + } + /** * Retrieve a proof record by connection id and thread id *