Build your own marketplace from scratch using Medusa
store_id
as on our previous entities
order_parent_id
column, which is nullable, allowing us to know whether an order has a parent or not
yarn build
and npx medusa migrations run
.
OrderService
Store
, and for the first time we’ll also see how to prevent a Store
from accessing an Order
that do not belongs to it :
WHERE
condition to our SQL query to target a specific store_id
if we have a logged in user with a store id.
For the retrieve
function, which allows us to retrieve an order, here we retrieve the Order with its associated store (or not, in the case of a parent Order) with the original function.
And we take care to validate after we have the Order, to compare the store_id
of the order with that of the logged-in user.
store_id
, they considered admin.src/subscribers
folder and name it orders
, so that all subscribers linked to orders will be inside.
We can now create the order-placed.ts
subscriber inside that new folder :
manager
.
The manager will enable us to create a transaction, which will be very useful here and we have already used in the previous part quickly.
completed
, in our example below.
In our example below, we’ll set the status of an Order
to complete
when :
payment_status
of completed
.
fulfillment_status
of completed
.
canceled
, archived
or already completed
index.d.ts
file created earlier, at this point, and what we have used, you should have an index.d.ts
file that looks like this :