def post_nr(nr: Request, svc: NameRequestService) -> Request: """ All logic for creating the name request goes inside this handler, which is invoked on successful state change. By default just call the inherited post_nr method. :param nr: The name request model :param svc A NameRequestService instance """ # Map the request data and save so we have a name request ID to use for collection ops nr = svc.map_request_data(nr, True) # Set map_draft_attrs to True nr = svc.save_request(nr) # Map applicants from the request data to the name request nr = svc.map_request_applicants(nr) # Map any submitted names from the request data to the name request nr = svc.map_request_names(nr) # Update the submit count to 1 nr = svc.update_request_submit_count(nr) # Save nr = svc.save_request(nr) # Return the updated name request return nr
def patch_nr(nr: Request, svc: NameRequestService, nr_action, request_data: dict) -> Request: """ Logic for updating the name request DATA goes inside this handler, which is invoked on successful state change. Re-map the names and the applicants (just the applicant / contact if applicable). :param nr: The name request model :param svc A NameRequestService instance :param nr_action: The Name Request action :param request_data: A request data object :return: """ lock_actions = [NameRequestPatchActions.CHECKIN.value, NameRequestPatchActions.CHECKOUT.value] if nr_action in lock_actions and nr.stateCd in [State.DRAFT, State.INPROGRESS]: # Map the checkout data nr.checkedOutBy = request_data.get('checkedOutBy', None) nr.checkedOutDt = request_data.get('checkedOutDt', None) nr = svc.save_request(nr) # Return the updated name request return nr if nr.stateCd in request_editable_states: # Map data from request_data to the name request map_draft_attrs = nr.stateCd == State.DRAFT nr = svc.map_request_data(nr, map_draft_attrs) # Map any submitted names from request_data to the name request nr = svc.map_request_names(nr) if nr.stateCd in contact_editable_states: # Map applicants from request_data to the name request nr = svc.map_request_applicants(nr) # Save nr = svc.save_request(nr) # Return the updated name request return nr
def put_nr(nr: Request, svc: NameRequestService) -> Request: """ Logic for updating the name request DATA goes inside this handler, which is invoked on successful state change. All request data is mapped. :param nr: The name request model :param svc A NameRequestService instance :return: """ map_draft_attrs = nr.stateCd == State.DRAFT nr = svc.map_request_data(nr, map_draft_attrs) # Map applicants from request_data to the name request nr = svc.map_request_applicants(nr) # Map any submitted names from request_data to the name request nr = svc.map_request_names(nr) # Save nr = svc.save_request(nr) # Return the updated name request return nr