Skip to content

Commit

Permalink
22774 consume names (bcgov#1563)
Browse files Browse the repository at this point in the history
* consider 'CONSUMED' state in state transition validation

* update the names for consumption

* update version
  • Loading branch information
eve-git authored Aug 21, 2024
1 parent e68f26f commit d40cd04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.2.1'
__version__ = '1.2.2'

25 changes: 25 additions & 0 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,31 @@ def patch(nr, *args, **kwargs):

nrd.furnished = 'Y'

def consumeName(nrd, json_input):
# Validate the required fields are present and not empty
name_to_consume = json_input.get('name')
if not name_to_consume \
or not json_input.get('consumptionDate') \
or not json_input.get('corpNum'):
return False, '"name", "consumptionDate", and "corpNum" are required and cannot be empty.'

consumed = False
for nrd_name in nrd.names:
if name_to_consume == nrd_name.name:
nrd_name.consumptionDate = json_input.get('consumptionDate')
nrd_name.corpNum = json_input.get('corpNum')
consumed = True

if not consumed:
return False, f"The given name '{name_to_consume}' cannot be found to be consumed."

return True, None # Return success and no error message

if state == State.CONSUMED:
success, error_message = consumeName(nrd, json_input)
if not success:
return make_response(jsonify(message=error_message), 406)

# save record
nrd.save_to_db()
EventRecorder.record(user, Event.PATCH, nrd, json_input)
Expand Down

0 comments on commit d40cd04

Please sign in to comment.