Fork me on GitHub
#duct
<
2022-03-14
>
mguinada18:03:21

Hi all! Is it possible to have some sort of duct component or module that does post-processing of the payload returned by another handler? I'm trying to do something like this:

[:money-clip.duct.restful/resource :money-clip.handler.bank-accounts/create]
 {:db #ig/ref :duct.database/sql
  :add {:user-id [:bank-account :user :id]}
  :exclude [[:bank-account :user]]
  :links {:self "/bank-account/{id}" :user "/users/{user-id}"}}
Where :money-clip.duct.restful/resource would be a generic post-processor - customisable by the :add / :exclude and :links options - for the map returned by the :money-clip.handler.bank-accounts/create handler. But I seem to be getting nowhere with it. What would be the duct way of achieving this or something similar? Thanks.

mguinada18:03:01

As it is now, I get the following error

Multiple methods in multimethod 'init-key' match dispatch value: :integrant.composite/money-clip.duct.restful.resource+money-clip.handler.bank-accounts.create_18632 -> :money-clip.handler.bank-accounts/create and :money-clip.duct.restful/resource, and neither is preferred

walterl22:03:15

I can think of 2 ways: 1) Split /resource and /create into separate components, such that the former refs the latter:

:money-clip.duct.restful/resource {:create #ig/ref :money-clip.handler.bank-accounts/create}
That way /resource can post-process the /create component. 2) Do post-processing in /create's init-key method on the component value that would've been returned.

mguinada11:03:58

Thanks @UJY23QLS1! Will definitely explore those two options.