Purpose
This WS is designed to change equipment status
Specification
Authorization
Verify the validity of access token
Return (401, 'Invalid access token') in case of validation fails
Verify that token is not expired
in case of error - return (401, 'Invalid access token')
Check user scopes in order to perform this action (scope = 'equipment:write')
Return (403, 'Your scope does not allow to access this resource. Missing allowances: equipment:write') in case of invalid scope(s)
If BLOCK_UNVERIFIED_PARTY_USERS is true, then check party's data match following condition: verification_status != NOT_VERIFIED or (verification_status = NOT_VERIFIED and updated_at > current_date - UNVERIFIED_PARTY_PERIOD_DAYS_ALLOWED):
in case not match - return 403 ("Access denied. Party is not verified")
If BLOCK_DECEASED_PARTY_USERS is true, check that party is not deceased (party_verification record does not equal to: dracs_death_verification_status = VERIFIED and dracs_death_verification_reason = MANUAL_CONFIRMED):
in case of error - return 403 ("Access denied. Party is deceased")
Validate equipment
Check that equipment with such ID exists in the system (is_active = true)
in case of error - return 404
Validate legal entity
Check that requested equipment belongs to the same legal entity as user
Extract
client_id
from tokenCheck that
equipments.legal_entity_id
==client_id
in case of error - return 403
Validate status transition
Check transition according to [NEW] Equipment status model
Get equipment by id
Check equipment status
If new status is inactive then current status must be active
If new status is entered_in_error then current status must be active or inactive
in case of error - return 409 ('Invalid transition. Equipment is in final status')
Validate request
Validate request by schema and return 422 error code with the list of validation errors in case of fails
Status
It is allowed to set only inactive
or entered_in_error
status. If status changes to incative
then availability_status
on device must be any but available
Validate $.status is one of the following (
inactive
|entered_in_error
)in case of error - return 422 ("value is not allowed in enum")
If $.status =
inactive
check that equipment.availability_status one of the following (damaged
|destroyed
|lost
)in case of error - return 409 ("It is prohibited to change status for equipment with availability status = {equipment.availability_status}")
Error_reason
If equipment status changes to entered_in_error
attribute error_reason
is required
If $.status =
entered_in_error
check that $.error_reason is passed in request and is not an empty stringin case of error - return 422 ('Error reason is required')
Validate $.error_reason is one of the following (dictionary: equipment_status_reasons)
in case of error - return 422 ("value is not allowed in enum")
Service logic
Update equipment record with the following:
status = $.status
error_reason = $.error_reason (optional)
updated_at = current datetime
updated_by = user_id from token