cr-connect-workflow/crc/api/approval.py

29 lines
1.0 KiB
Python
Raw Normal View History

from crc import app, db, session
2020-05-24 05:53:48 +00:00
from crc.api.common import ApiError, ApiErrorSchema
from crc.models.approval import Approval, ApprovalModel, ApprovalSchema
from crc.services.approval_service import ApprovalService
def get_approvals(approver_uid = None):
2020-05-24 05:53:48 +00:00
db_approvals = ApprovalService.get_all_approvals()
approvals = [Approval.from_model(approval_model) for approval_model in db_approvals]
results = ApprovalSchema(many=True).dump(approvals)
return results
2020-05-24 05:53:48 +00:00
def update_approval(approval_id, body):
if approval_id is None:
raise ApiError('unknown_approval', 'Please provide a valid Approval ID.')
approval_model = session.query(ApprovalModel).get(approval_id)
if approval_model is None:
2020-05-24 05:53:48 +00:00
raise ApiError('unknown_approval', 'The approval "' + str(approval_id) + '" is not recognized.')
approval: Approval = ApprovalSchema().load(body)
approval.update_model(approval_model)
session.add(approval_model)
session.commit()
2020-05-24 05:53:48 +00:00
result = ApprovalSchema().dump(approval)
return result