diff --git a/internal/dataagreement_record/db.go b/internal/dataagreement_record/db.go index 20ddcec..ac4d515 100644 --- a/internal/dataagreement_record/db.go +++ b/internal/dataagreement_record/db.go @@ -74,18 +74,11 @@ func (darRepo *DataAgreementRecordRepository) GetByDataAgreementIdandIndividualI } // Deletes all the data agreement records of individual -func (darRepo *DataAgreementRecordRepository) DeleteAllRecordsForIndividual(individualId string) error { +func (darRepo *DataAgreementRecordRepository) DeleteAllRecordsForIndividual(individualId string, organisationId string) error { - filter := common.CombineFilters(darRepo.DefaultFilter, bson.M{"individualid": individualId}) + filter := bson.M{"organisationid": organisationId, "individualid": individualId} - // Update to set IsDeleted to true - update := bson.M{ - "$set": bson.M{ - "isdeleted": true, - }, - } - - _, err := Collection().UpdateMany(context.TODO(), filter, update) + _, err := Collection().DeleteMany(context.TODO(), filter) return err } diff --git a/internal/handler/v2/service/service_delete_individual_dataagreement_records.go b/internal/handler/v2/service/service_delete_individual_dataagreement_records.go index a54fbec..5311d1f 100644 --- a/internal/handler/v2/service/service_delete_individual_dataagreement_records.go +++ b/internal/handler/v2/service/service_delete_individual_dataagreement_records.go @@ -18,7 +18,7 @@ func ServiceDeleteIndividualDataAgreementRecords(w http.ResponseWriter, r *http. darRepo := daRecord.DataAgreementRecordRepository{} darRepo.Init(organisationId) - err := darRepo.DeleteAllRecordsForIndividual(individualId) + err := darRepo.DeleteAllRecordsForIndividual(individualId, organisationId) if err != nil { m := "Failed to delete data agreement records for individual" common.HandleErrorV2(w, http.StatusInternalServerError, m, err)