ЕСОЗ - публічна документація

RC_[NEW] Change equipment status

Purpose

This WS is designed to change equipment status

Specification

Apiary

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 token

  • Check 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

  1. Validate $.status is one of the following (inactive | entered_in_error)

    1. in case of error - return 422 ("value is not allowed in enum")

Error_reason

If equipment status changes to entered_in_error attribute error_reason is required

  1. If $.status = entered_in_error check that $.error_reason is passed in request and is not an empty string

    1. in case of error - return 422 ('Error reason is required')

  2. Validate $.error_reason is one of the following (dictionary: equipment_status_reasons)

    1. in case of error - return 422 ("value is not allowed in enum")

Service logic

  1. Update equipment record with the following:

    1. status = $.status

    2. error_reason = $.error_reason (optional)

    3. updated_at = current datetime

    4. updated_by = user_id from token

ЕСОЗ - публічна документація