#How do I add two controller to one route ?
120 messages · Page 1 of 1 (latest)
You can create a middleware or a route with just the handler
how would it be written in case of handler ?
also how can I call a medusa core controller ?
inside hanndlers array
Yes you can, but the only thing you need to add in your function is to call next for the next handler to be called i.e the one from medusa
I think the easier way is to write a middleware
You don’t have to call the original handler yiuself
In both cases, you call next in your handler and express will move to the next handler for that route normally
in POST /carts/{id}/complete if I need to add store_id value for Order, how do I approach this situation ?
I haven't overriden the function
I did a migration on the Order entity
and added column store_id I just need to add the store_id value to Order after calling this api
You could add the store id on the cart metadata which are assigned to the order metadata. Then you could create a subscriber on the placed event to assign it to the order
When you want to do such customization, i suggest you to look at the core implementation. That way you can find multiple solutions and just use the one that fits you best 😀 and you can learn 1-2 things on the way
You can look at the order service createFromCart
I thought maybe I can copy paste what's on github and add what needs to be added
Only for heavy customisation as it comes with some drawbacks
Most of the times it is not needed, it is a bad practice and only applicable in case where you want to do some heavy customisation
Which is why it requires to be advanced in programming to avoid accumulating bad practices and ending up with something that conflicts all the time or become hard to scale or evolve 😅
Yes sure 👌
That is also a good idea 👌🤘
Good point
Before insert you don’t need the request if the store id is in the cart metadata
I am in vacantion so ill not be able to help a lot
this is how I was doing it
ahhhh
on create cart
i just add to metadata column {store_id:1231}
Yes exactly
then in beforeInsert in order I refetch the cart using retrieve and do what is needed?
or am I complicating it ?
since I have the cart id in path
No in before insert the cart_id will be on the order metadata so you just re assign it on the order as well
No need to re fetch it
Thanks a lot you too 😍
ok last question
now I can see in the db that the store_id is saving in the metadata of order entity
how to assign it ?
You can look at the doc for that 😅
aight
Order, since you want to listen before insert of the order
It is a typo 😂 as you might notice ahah
ah ok
If you can either open an issue or a pr it would be cool 😀
will do regarding it no worries
this is the metadata inside my cart
I still kinda can't understand how to read the data from the metadata :p
What do you mean?
You can do your order.store_id = order.metadata.store_id or something similar depending on your needs
It is just an object ahah
this is what I was trying to do
Your are stringifying the metadata therefore it is a string. Why are you doing that?
stringify is wrong
yeah yeah ik
by accident
I removed it
I just need the line that assigns store_id for order
I was trying to log but somehow it isnt logging in the terminal as if its not getting there
do I need to include subscribers in my order module ?
Yes you do
Oh sorry you mean the event subscriber ?
If yes then no you don’t. But did you add the little snippet in the service constructor?
yes
the listenTo ?
attach(
yes
ok so its logging correctly
but I just need to know how to assign it to the order
what do I do
:p ?
the error is because
Record <String, unknown>
as string 😅
store_id has an unknown type in metadata
I mean I could insert it in a variable of type any but I don't think I would solve any issue
Yes so cast it to a string since you know it is a string
just + "" ?
Or just - as string - as i said
Or you can look at the ts doc ahah
Those are more related to ts than medusa or the extender
shouldnt the record have type of String, any ?
No since since we don’t know it is better to type as unknown
It forces you to type it with what you know it is or to check the type of it
With any, it could be an object and you wouldn’t even know that you are assigning an object to a string
Not abstract just unknown ahah
Ahah not the right word
I am in holiday so ill answer later to this question ahah