Skip to content

Commit

Permalink
Fix #579 Add individual header to service fetch consent records for d…
Browse files Browse the repository at this point in the history
…ata agreement endpoint
  • Loading branch information
albinpa authored and georgepadayatti committed Nov 21, 2023
1 parent 08f30e4 commit 9666cbe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/dataagreement_record/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ func CreatePipelineForFilteringDataAgreementRecordsByIndividualId(organisationId
}

// CreatePipelineForFilteringDataAgreementRecordsByDataAgreementId This pipeline is used for filtering data agreement records by data agreement id
func CreatePipelineForFilteringDataAgreementRecordsByDataAgreementId(organisationId string, dataAgreementId string) ([]primitive.M, error) {
func CreatePipelineForFilteringDataAgreementRecordsByDataAgreementId(organisationId string, dataAgreementId string, individualId string) ([]primitive.M, error) {

var pipeline []bson.M

// Stage 1 - Match by `organisationId`, `dataagreementId` and `isDeleted=false`
pipeline = append(pipeline, bson.M{"$match": bson.M{"organisationid": organisationId, "isdeleted": false, "dataagreementid": dataAgreementId}})
pipeline = append(pipeline, bson.M{"$match": bson.M{"organisationid": organisationId, "isdeleted": false, "dataagreementid": dataAgreementId, "individualid": individualId}})

// Stage 2 - Lookup revision by `dataAgreementRecordId`
// This is done to obtain timestamp for the latest revision of the data agreement records.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func ServiceFetchRecordsForDataAgreement(w http.ResponseWriter, r *http.Request)

// Headers
organisationId := common.Sanitize(r.Header.Get(config.OrganizationId))
individualId := common.Sanitize(r.Header.Get(config.IndividualHeaderKey))
dataAgreementId := common.Sanitize(mux.Vars(r)[config.DataAgreementId])

// Query params
Expand All @@ -33,7 +34,7 @@ func ServiceFetchRecordsForDataAgreement(w http.ResponseWriter, r *http.Request)
darRepo := daRecord.DataAgreementRecordRepository{}
darRepo.Init(organisationId)

pipeline, err := daRecord.CreatePipelineForFilteringDataAgreementRecordsByDataAgreementId(organisationId, dataAgreementId)
pipeline, err := daRecord.CreatePipelineForFilteringDataAgreementRecordsByDataAgreementId(organisationId, dataAgreementId, individualId)
if err != nil {
m := "Failed to create pipeline"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
Expand Down

0 comments on commit 9666cbe

Please sign in to comment.