Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(order): module foundation #6399

Merged
merged 10 commits into from
Feb 15, 2024
Merged

feat(order): module foundation #6399

merged 10 commits into from
Feb 15, 2024

Conversation

carlos-r-l-rodrigues
Copy link
Contributor

What:
Initial Order module foundation.
Basic models and methods to manage entites like in Cart Module

@carlos-r-l-rodrigues carlos-r-l-rodrigues requested review from a team as code owners February 14, 2024 15:40
Copy link

changeset-bot bot commented Feb 14, 2024

🦋 Changeset detected

Latest commit: 900fc71

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@medusajs/modules-sdk Patch
@medusajs/types Patch
@medusajs/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2024 0:44am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Feb 15, 2024 0:44am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Feb 15, 2024 0:44am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Feb 15, 2024 0:44am

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discuss, we can continue from there, things will change later but it gives us a structure to work from 👍

packages/order/README.md Outdated Show resolved Hide resolved
packages/order/src/models/adjustment-line.ts Outdated Show resolved Hide resolved
Comment on lines +57 to +73
return {
toString: () => {
return expression
},
valueOf: () => {
return expression
},
name,
expression,
MikroORMIndex: (options = {}) => {
return Index({
name,
expression,
...options,
})
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What's the idea here? And why did we change the fulfillment (among others) module indexes? Seems weird to have a discrepancy here.

Copy link
Member

@adrien2p adrien2p Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to be able to construct the index object and immediately apply it to the props without having to explicitly declared a name and build the expression and then having to apply them all.

const Index = createPsqlIndexHelper({
  name: "IDX",
  ...
})

class Entity {
  @Index.MikroORMIndex()
  prop: something
}

instead of

const indexName = 'IDX'
const index = createPsqlIndexHelper({
  name: indexName,
  ...
})

class Entity {
  @Index({
    name: indexName,
    expression: index
  })
  prop: something
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I realise I phrased my question wrong. Why do we need the different return values and why are we not using it the same why in the modules?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have a need for the values for example like in the customer module where you need to index name in order to handle the error manually, in that case this index is exported and you can extract the name from it. The expression could be also needed why not. The idea was to not fully changed the other modules in order to reduce the amount of conflict. So the other modules are just extracting the expression so that only the indexes are touched and not the entities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to change the default behavior of the helper, and regardless the ORM used, the expression in plain sql might be needed.
I will refactor all the other modules in a next PR. as Adrien said, I'm avoiding a big number of conflicts for now.

Copy link
Collaborator

@srindom srindom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM w. comments

): Promise<OrderTypes.OrderLineItemDTO[]>

@InjectManager("baseRepository_")
async addLineItems(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: we should probably have a check here eventually that verifies that the order is in a state where it's allowed to have line items added externally. For example, once the order is placed adding line items should go through the mechanism we come up with for edits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar thinking for some of the other functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I am just avoiding in this PR handle things that are uncertain.
When we define the order edits, and what will be the rules, all these services will have to be revisited anyway.
In theory we could have multiple versions of the same order and the service will have to handle/validate that.
Same for the field placed_at. I will wait more definition how we'll manage order changes to change that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep all good!

@@ -0,0 +1,31 @@
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: shouldn't this be in types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately enums are transpiled to objects. and things that generate code we have to move to utils.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the approach so far is having an enum in the utils and a type in the types

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

packages/order/src/models/order.ts Show resolved Hide resolved
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great piece of work!

@olivermrbl olivermrbl changed the title Feat(order): module foundation feat(order): module foundation Feb 15, 2024
@kodiakhq kodiakhq bot merged commit 339a946 into develop Feb 15, 2024
17 checks passed
@kodiakhq kodiakhq bot deleted the feat/order-module branch February 15, 2024 13:26
@github-actions github-actions bot mentioned this pull request Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants