Skip to content

Commit

Permalink
Make webhooks payload truly iso with v1 and more robust
Browse files Browse the repository at this point in the history
1. intitule/description is not required and can't be undefined for some
   authorization requests
2. `contacts` was renamed `team_members`
3. `demarche` is an id, not a name
4. `team_members` has the applicant as "demandeur"
  • Loading branch information
skelz0r committed Mar 28, 2024
1 parent ff9bd1c commit a507158
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions app/serializers/webhook_authorization_request_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class WebhookAuthorizationRequestSerializer < ApplicationSerializer
:previous_authorization_request_id,
:copied_from_authorization_request_id

has_many(:contacts, serializer: ContactSerializer)
has_many(:events, serializer: WebhookEventSerializer) do
object.events.map(&:decorate)
end
Expand All @@ -18,9 +17,29 @@ class WebhookAuthorizationRequestSerializer < ApplicationSerializer
object.scopes.to_h { |scope| [scope.to_sym, true] }
end

def demarche = object.form.name
def status = object.state
def siret = object.organization.siret
def intitule = object.data['intitule']
def description = object.data['description']
def demarche = object.form.id
def status = object.state
def siret = object.organization.siret

def team_members
object.contacts.map do |contact|
ContactSerializer.new(contact).serializable_hash
end << applicant_as_team_member
end

def applicant_as_team_member
{
id: nil,
type: 'demandeur',
email: object.applicant.email,
given_name: object.applicant.given_name,
family_name: object.applicant.family_name,
phone_number: object.applicant.phone_number,
job: object.applicant.job_title,
}
end

def previous_authorization_request_id = nil
def copied_from_authorization_request_id = nil
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/webhook_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def to_json(*_args)
private

def model_type
authorization_request.class.name.underscore
"enrollment/#{authorization_request.class.name.underscore.split('/').last}"
end

def now
Expand Down

0 comments on commit a507158

Please sign in to comment.