diff --git a/unit/api/application_resource.py b/unit/api/application_resource.py index 683dfff6..29051e0f 100644 --- a/unit/api/application_resource.py +++ b/unit/api/application_resource.py @@ -61,3 +61,21 @@ def upload(self, request: UploadDocumentRequest): return UnitResponse[ApplicationDocumentDTO](DtoDecoder.decode(data), None) else: return UnitError.from_json_api(response.json()) + + def approve_sb(self, request: ApproveApplicationSBRequest): + url = f"sandbox/{self.resource}/{request.application_id}/approve" + + payload = request.to_json_api() + response = super().post(url, payload) + + if response.ok: + data = response.json().get("data") + included = response.json().get("included") + return UnitResponse(data, included) + # TODO need DTOs for this response + # if data["type"] == "individualApplication": + # return UnitResponse[IndividualApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included)) + # else: + # return UnitResponse[BusinessApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included)) + else: + return UnitError.from_json_api(response.json()) \ No newline at end of file diff --git a/unit/models/application.py b/unit/models/application.py index 60f5a5c9..98744681 100644 --- a/unit/models/application.py +++ b/unit/models/application.py @@ -258,3 +258,21 @@ def to_dict(self) -> Dict: if self.sort: parameters["sort"] = self.sort return parameters + +class ApproveApplicationSBRequest(UnitRequest): + def __init__(self, application_id: str): + self.application_id = application_id + + def to_json_api(self) -> Dict: + payload = { + "data": { + "type": "applicationApprove", + "attributes": { + "reason": "sandbox" + } + } + } + return payload + + def __repr__(self): + json.dumps(self.to_json_api())