From 9fa6c6daf77ac56b9bc83ae3bfdae72cd919bc6c Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht <61358536+blu3beri@users.noreply.github.com> Date: Tue, 10 Aug 2021 12:34:47 +0200 Subject: [PATCH] feat(redux): delete credentialRecord and proofRecord (#421) Signed-off-by: Berend Sliedrecht --- .../src/slices/connections/connectionsSlice.ts | 1 + .../src/slices/connections/connectionsThunks.ts | 2 +- .../src/slices/credentials/credentialsSlice.ts | 6 ++++++ .../src/slices/credentials/credentialsThunks.ts | 12 ++++++++++++ .../redux-store/src/slices/proofs/proofsSlice.ts | 6 ++++++ .../redux-store/src/slices/proofs/proofsThunks.ts | 11 +++++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/redux-store/src/slices/connections/connectionsSlice.ts b/packages/redux-store/src/slices/connections/connectionsSlice.ts index 0b38218140..76d6b4f33a 100644 --- a/packages/redux-store/src/slices/connections/connectionsSlice.ts +++ b/packages/redux-store/src/slices/connections/connectionsSlice.ts @@ -111,6 +111,7 @@ const connectionsSlice = createSlice({ .addCase(ConnectionThunks.acceptInvitation.fulfilled, (state) => { state.invitation.isLoading = false }) + // deleteConnection .addCase(ConnectionThunks.deleteConnection.fulfilled, (state, action) => { const connectionId = action.payload.id const index = state.connections.records.findIndex((connectionRecord) => connectionRecord.id === connectionId) diff --git a/packages/redux-store/src/slices/connections/connectionsThunks.ts b/packages/redux-store/src/slices/connections/connectionsThunks.ts index 849a0681ab..81081b0c63 100644 --- a/packages/redux-store/src/slices/connections/connectionsThunks.ts +++ b/packages/redux-store/src/slices/connections/connectionsThunks.ts @@ -97,7 +97,7 @@ const ConnectionThunks = { ), /** - * Deletes a connectionRecord in the connectionRepository + * Deletes a connectionRecord in the connectionRepository. */ deleteConnection: createAsyncAgentThunk('connections/deleteConnection', async (connectionId: string, thunksApi) => { const connectionRepository = thunksApi.extra.agent.injectionContainer.resolve(ConnectionRepository) diff --git a/packages/redux-store/src/slices/credentials/credentialsSlice.ts b/packages/redux-store/src/slices/credentials/credentialsSlice.ts index d7bb01279a..3b0b1ac2c0 100644 --- a/packages/redux-store/src/slices/credentials/credentialsSlice.ts +++ b/packages/redux-store/src/slices/credentials/credentialsSlice.ts @@ -77,6 +77,12 @@ const credentialsSlice = createSlice({ .addCase(CredentialsThunks.acceptCredential.rejected, (state, action) => { state.error = action.error }) + // deleteCredential + .addCase(CredentialsThunks.deletCredential.fulfilled, (state, action) => { + const credentialId = action.payload.id + const index = state.credentials.records.findIndex((record) => record.id == credentialId) + state.credentials.records.splice(index, 1) + }) }, }) diff --git a/packages/redux-store/src/slices/credentials/credentialsThunks.ts b/packages/redux-store/src/slices/credentials/credentialsThunks.ts index 3c9436607c..513d883666 100644 --- a/packages/redux-store/src/slices/credentials/credentialsThunks.ts +++ b/packages/redux-store/src/slices/credentials/credentialsThunks.ts @@ -1,6 +1,8 @@ import type { ClassMethodParameters } from '../../utils' import type { CredentialsModule } from '@aries-framework/core' +import { CredentialRepository } from '@aries-framework/core' + import { createAsyncAgentThunk } from '../../utils' /** @@ -121,6 +123,16 @@ const CredentialsThunks = { acceptCredential: createAsyncAgentThunk('credentials/acceptCredential', async (credentialId: string, thunkApi) => { return thunkApi.extra.agent.credentials.acceptCredential(credentialId) }), + + /** + * Deletes a credentialRecord in the credential repository. + */ + deletCredential: createAsyncAgentThunk('credentials/deleteCredential', async (credentialId: string, thunkApi) => { + const credentialRepository = thunkApi.extra.agent.injectionContainer.resolve(CredentialRepository) + const credentialRecord = await credentialRepository.getById(credentialId) + await credentialRepository.delete(credentialRecord) + return credentialRecord + }), } export { CredentialsThunks } diff --git a/packages/redux-store/src/slices/proofs/proofsSlice.ts b/packages/redux-store/src/slices/proofs/proofsSlice.ts index 5d15667cdb..2bc147f131 100644 --- a/packages/redux-store/src/slices/proofs/proofsSlice.ts +++ b/packages/redux-store/src/slices/proofs/proofsSlice.ts @@ -81,6 +81,12 @@ const proofsSlice = createSlice({ .addCase(ProofsThunks.autoSelectCredentialsForProofRequest.rejected, (state, action) => { state.error = action.error }) + // deleteProof + .addCase(ProofsThunks.deletCredential.fulfilled, (state, action) => { + const proofId = action.payload.id + const index = state.proofs.records.findIndex((record) => record.id == proofId) + state.proofs.records.splice(index, 1) + }) }, }) diff --git a/packages/redux-store/src/slices/proofs/proofsThunks.ts b/packages/redux-store/src/slices/proofs/proofsThunks.ts index db7a46b8f5..810d041bad 100644 --- a/packages/redux-store/src/slices/proofs/proofsThunks.ts +++ b/packages/redux-store/src/slices/proofs/proofsThunks.ts @@ -1,6 +1,8 @@ import type { ClassMethodParameters } from '../../utils' import type { RequestedCredentials, ProofsModule, RetrievedCredentials } from '@aries-framework/core' +import { ProofRepository } from '@aries-framework/core' + import { createAsyncAgentThunk } from '../../utils' /** @@ -142,6 +144,15 @@ const ProofsThunks = { return thunkApi.extra.agent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials) } ), + /** + * Deletes a proofRecord in the proof repository. + */ + deletCredential: createAsyncAgentThunk('proofs/deleteProof', async (proofId: string, thunkApi) => { + const proofRepository = thunkApi.extra.agent.injectionContainer.resolve(ProofRepository) + const proofRecord = await proofRepository.getById(proofId) + await proofRepository.delete(proofRecord) + return proofRecord + }), } export { ProofsThunks }