Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Changed members-api constructor to accept Member model directly #105

Merged
merged 1 commit into from
Dec 5, 2019

Conversation

naz
Copy link
Contributor

@naz naz commented Nov 28, 2019

Refactor that allows member-api to use Ghost member models directly, also reduces member-api constructor signature.

Note: would require a minor bump because of the constructor signature change

@allouis would be great if you could verify if I understood the needed refactor correctly and this is the right direction ▶️

no issue

- As members have become a part of Ghost core there is no need to proxy methods like this anymore and we can allow members-api to work on the model directly
- Methods come from Ghost core: https://github.com/TryGhost/Ghost/blob/cc39786/core/server/services/members/api.js#L11-L110
@naz naz requested a review from allouis November 28, 2019 10:18
@naz naz marked this pull request as ready for review November 28, 2019 10:23
Copy link
Collaborator

@allouis allouis left a comment

Choose a reason for hiding this comment

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

This is exactly the right direction of change 👍

Couple of points/ideas to think about, and these are just opinions, so take them as that ☺️

  • IMO the custom logic we have in createMember etc.. functions can be moved to the member model (e.g. default null for name/note) OR the members-api can be updated to deal with what the model expects/returns (though i still thinking calling toJSON is a good idea, dealing with plain objects is nice IMO 🤷‍♂️)

  • maybe the getMetadata fn can be removed eventually and the member model can use some kind of relation plugin thing so that we can do withRelated: stripeInfoStuff?

  • maybe we eventually pass a model to the stripe module? maybe the member model, or maybe just the stripe related ones?

The idea behind passing in the functions before was so that members-api has NO idea what the datastore or model layer is, it just takes super basic functions that should never throw, just resolve with object or null - now that members is a core thing in Ghost, it's totally acceptable, and preferred that it used the same constructs as we do in Ghost.

The goal of this ticket is to remove as much "indirection" as possible with two main parts:

  1. Ghost core should be able to just use the model layer
  2. Members core should be able to just use the model layer

Obviously there's a long road to that, and this is a perfect start IMO

naz added a commit to naz/Ghost that referenced this pull request Dec 3, 2019
no issue

- These methods have benn moved ton @tryghost/members-api in favor of using the model directly (ref: TryGhost/Members#105)
@naz
Copy link
Contributor Author

naz commented Dec 3, 2019

IMO the custom logic we have in createMember etc.. functions can be moved to the member model (e.g. default null for name/note) OR the members-api can be updated to deal with what the model expects/returns (though i still thinking calling toJSON is a good idea, dealing with plain objects is nice IMO man_shrugging)

Moving this kind of logic into the model 💯 makes sense! As for toJSON in the service layer... I don't have a strong opinion. It's not supposed to be called most of the time in controllers so that serializers can deal with options for toJSON call in the way they need. As long as the results from the service are not returned directly by the controller it should be fine to use it.

maybe the getMetadata fn can be removed eventually and the member model can use some kind of relation plugin thing so that we can do withRelated: stripeInfoStuff?

Wow. Just looked into this method and we definitely want to do it in a proper relational way 😬 The filter by member_id and reducing over the returned customer is def. not a nice way to do it 😂

maybe we eventually pass a model to the stripe module? maybe the member model, or maybe just the stripe related ones?

Which module do you have in mind exactly?

Thanks for the feedback! Will try moving the refactor in this direction bit by bit. Think it could become a nice blueprint in the end on how we could refactor out more of the modules out of Ghost core with their specialized functionalities in the future.

@allouis
Copy link
Collaborator

allouis commented Dec 5, 2019

Wow. Just looked into this method

😂 I fucking hate bookshelf relation plugin bullshit!! I spent a day on it and just went with this 😠

Which module do you have in mind exactly?

The lib/stripe one 😛

Think it could become a nice blueprint in the end on how we could refactor out more of the modules out of Ghost core

Yeah, same! I'm hoping it's small enough that it's not super confusing, but complex it enough that we can apply the same techniques to the rest of Ghost 💪

@naz naz merged commit a733d52 into TryGhost:master Dec 5, 2019
naz added a commit to TryGhost/Ghost that referenced this pull request Dec 6, 2019
no issue

- This includes the interface change for members-api constructor - now accepts the member's model instead of proxy methods. These methods have been moved ton @tryghost/members-api in favor of using the model directly (ref: TryGhost/Members#105)
- Moved error handling from the service layer to controller
- Bumped @tryghost/member-api package to 0.10.0
naz added a commit to naz/Members that referenced this pull request Jan 9, 2020
- This is the refactor similar to what has been done with Memeber model being passed in directly in the constructor
- Relevent discussion here TryGhost#105 (review)
naz added a commit to naz/Members that referenced this pull request Jan 13, 2020
- This is the refactor similar to what has been done with Memeber model being passed in directly in the constructor
- Relevent discussion here TryGhost#105 (review)
naz added a commit that referenced this pull request Jan 13, 2020
no issue

- This is the refactor similar to what has been done with Memeber model being passed in directly in the constructor
- Relevent discussion here #105 (review)
naz added a commit that referenced this pull request Jan 15, 2020
refs #105

- It's a follow up to a series of refactorings in the module mostly discussed in refed PR
- The sendEmailWithMagicLink and destroyStripeSubscriptions were exposed through members API so that Ghost  could call it from the controller level
naz added a commit to naz/Ghost that referenced this pull request Jan 15, 2020
refs TryGhost/Members#105

- Needs a version bump for @tryghost/members-api to use getStripeSubscriptions method
- This new method is a little hacky because there are no relationships setup on members_* tables
naz added a commit to TryGhost/Ghost that referenced this pull request Jan 15, 2020
refs TryGhost/Members#105

- As members module has become a core part it makes sense to follow the same principles as in all other controllers and use the model directly instead of calling external services.
- Bumped @tryghost/members-api to 0.11.1 . New stripe-specific methods used in controllers are available starting with this version
- Exposing these new methods is a little hacky because there are no relationships setup on members_* tables. Left notes for future improvements once relations are introduced.
- We don't allow for chaging member's emails at the moment. For this reason had to modify JSON schema a little. It doesn't support OO inheritence: "This shortcoming is perhaps one of the biggest surprises of the combining operations in JSON schema: it does not behave like inheritance in an object-oriented language. " (ref. https://json-schema.org/understanding-json-schema/reference/combining.html#allof)
naz added a commit to naz/Ghost-SDK that referenced this pull request Sep 24, 2020
refs TryGhost/Members#105

- As members module has become a core part it makes sense to follow the same principles as in all other controllers and use the model directly instead of calling external services.
- Bumped @tryghost/members-api to 0.11.1 . New stripe-specific methods used in controllers are available starting with this version
- Exposing these new methods is a little hacky because there are no relationships setup on members_* tables. Left notes for future improvements once relations are introduced.
- We don't allow for chaging member's emails at the moment. For this reason had to modify JSON schema a little. It doesn't support OO inheritence: "This shortcoming is perhaps one of the biggest surprises of the combining operations in JSON schema: it does not behave like inheritance in an object-oriented language. " (ref. https://json-schema.org/understanding-json-schema/reference/combining.html#allof)
naz added a commit to naz/Ghost-SDK that referenced this pull request Sep 28, 2020
refs TryGhost/Members#105

- As members module has become a core part it makes sense to follow the same principles as in all other controllers and use the model directly instead of calling external services.
- Bumped @tryghost/members-api to 0.11.1 . New stripe-specific methods used in controllers are available starting with this version
- Exposing these new methods is a little hacky because there are no relationships setup on members_* tables. Left notes for future improvements once relations are introduced.
- We don't allow for chaging member's emails at the moment. For this reason had to modify JSON schema a little. It doesn't support OO inheritence: "This shortcoming is perhaps one of the biggest surprises of the combining operations in JSON schema: it does not behave like inheritance in an object-oriented language. " (ref. https://json-schema.org/understanding-json-schema/reference/combining.html#allof)
daniellockyer pushed a commit to TryGhost/Ghost that referenced this pull request Jul 20, 2022
no issue

- This is the refactor similar to what has been done with Memeber model being passed in directly in the constructor
- Relevent discussion here TryGhost/Members#105 (review)
daniellockyer pushed a commit to TryGhost/Ghost that referenced this pull request Jul 20, 2022
refs TryGhost/Members#105

- It's a follow up to a series of refactorings in the module mostly discussed in refed PR
- The sendEmailWithMagicLink and destroyStripeSubscriptions were exposed through members API so that Ghost  could call it from the controller level
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants