Skip to content

Commit

Permalink
Fix #214: Opt-in/out not working for newly created data agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumthasir mohammed committed Feb 22, 2024
1 parent 13be232 commit aa3b7a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

// MARK: - Records
class RecordsModel: Codable {
let consentRecords: [ConsentRecordModel]
var consentRecords: [ConsentRecordModel]
let pagination: RecordsPagination
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,18 @@ class BBConsentOrganisationViewController: BBConsentBaseViewController {
}
}

func callCreateDataAgreementApi(dataAgreementId: String) {
func callCreateDataAgreementApi(dataAgreementId: String, completion: @escaping(ConsentRecordModel?)-> Void) {
let url = baseUrl + "/service/individual/record/data-agreement/" + dataAgreementId
self.api.makeAPICall(urlString: url, method:.post) { status, result in
debugPrint(status)
self.orgTableView.reloadData()
if status {
let jsonDecoder = JSONDecoder()
debugPrint(result["consentRecord"] ?? [:])
if let data = try? JSONSerialization.data(withJSONObject: result["consentRecord"] ?? [:], options: .prettyPrinted) {
let model = try? jsonDecoder.decode(ConsentRecordModel.self, from: data)
debugPrint("### ConsentRecordModel:\(String(describing: model))")
completion(model)
}
}
}
}

Expand All @@ -137,7 +144,7 @@ class BBConsentOrganisationViewController: BBConsentBaseViewController {
// If item doesnt have record already
if !idsWithAttributeRecords.contains(item) {
// Create add record api call
callCreateDataAgreementApi(dataAgreementId: item)
callCreateDataAgreementApi(dataAgreementId: item) { _ in }
}
}
}
Expand Down Expand Up @@ -412,7 +419,12 @@ extension BBConsentOrganisationViewController: ExpandableLabelDelegate ,PurposeC
}
})
} else {
serviceManager.createDataAgreementRecord(dataAgreementId: self.dataAgreementsObj?.dataAgreements[cell.tag].id ?? "")
self.callCreateDataAgreementApi(dataAgreementId: self.dataAgreementsObj?.dataAgreements[cell.tag].id ?? "") { model in
if let consentRecordModel = model {
self.consentRecordsObj?.consentRecords.append(consentRecordModel)
self.orgTableView.reloadData()
}
}
}
}));
}
Expand Down

0 comments on commit aa3b7a4

Please sign in to comment.