Skip to content

Commit

Permalink
Fix #394 Delete data agreement records for a data agreement if that d…
Browse files Browse the repository at this point in the history
…ata agreement is deleted
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 27, 2023
1 parent 932454e commit 991e329
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/v2/dataagreement_record/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,19 @@ func PipelineForList(organisationId string, id string, lawfulBasis string, isId

return pipeline, nil
}

// Deletes all the data agreement records for data agreement id
func (darRepo *DataAgreementRecordRepository) DeleteDataAgreementRecordsForDataAgreement(dataAgreementId string) error {
filter := common.CombineFilters(darRepo.DefaultFilter, bson.M{"dataagreementid": dataAgreementId})

// Update to set IsDeleted to true
update := bson.M{
"$set": bson.M{
"isdeleted": true,
},
}

_, err := Collection().UpdateMany(context.TODO(), filter, update)

return err
}
13 changes: 13 additions & 0 deletions src/v2/handler/dataagreement/config_delete_dataagreement.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/bb-consent/api/src/common"
"github.com/bb-consent/api/src/config"
"github.com/bb-consent/api/src/v2/dataagreement"
daRecord "github.com/bb-consent/api/src/v2/dataagreement_record"
"github.com/bb-consent/api/src/v2/dataattribute"
"github.com/bb-consent/api/src/v2/revision"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -61,6 +62,18 @@ func ConfigDeleteDataAgreement(w http.ResponseWriter, r *http.Request) {
return
}

// Repository
darRepo := daRecord.DataAgreementRecordRepository{}
darRepo.Init(organisationId)

// Deletes all the data agreement records for data agreement id
err = darRepo.DeleteDataAgreementRecordsForDataAgreement(dataAgreementId)
if err != nil {
m := fmt.Sprintf("Failed to delete data agreement id from data agreement records: %v", dataAgreementId)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}

_, err = daRepo.Update(currentDataAgreement)
if err != nil {
m := fmt.Sprintf("Failed to delete data agreement: %v", dataAgreementId)
Expand Down

0 comments on commit 991e329

Please sign in to comment.