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

StakeRequest model (with a help of sequelize) #73

Merged
merged 32 commits into from
Jun 21, 2019

Conversation

pgev
Copy link
Contributor

@pgev pgev commented Jun 19, 2019

Implements stake request model classes.

StakeRequestAttributes: Represents an interface for an input to create StakeRequest objects in StakeRequestRepository.

StakeRequest: Represents a stake request object to be used throughout facilitator.

StakeRequestModel: Represents a StakeRequest database model. Allows to initialize stake request database table's schema and in addition represents a raw in that table.

StakeRequestRepository: Allows to create and retrieve stake request object. A class should be an interface for other classes in facilitator to interact with stake request model.

Database: Creates, initializes and gives an access to different models throughout facilitator.

Fixes: #53

Copy link
Contributor

@deepesh-kn deepesh-kn left a comment

Choose a reason for hiding this comment

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

This looks very clean 👍

Questions:

  1. Why do we need StakeRequestAttributes? Is it that any class that implement the StakeRequestAttributes interface can be passed in the build and create params?

  2. What StakeRequestRepository.build does?

  3. What do you think if we do the following?

    • StakeRequestRepository can extends Model
    • StakeRequestModel can be a simple class that has all the properties (may be some functions to implement business logic). Implements/confirms to the StakeRequestAttributes interface.
    • StakeRequestModel can be passed as params in StakeRequestRepository.build and StakeRequestRepository.create
    • StakeRequestModel is returned from StakeRequestRepository.get function.

In this way there is clear separation of Model objects(related to facilitator) and Repository (sequelize model objects)

Paruyr Gevorgyan added 6 commits June 19, 2019 16:06
  - Hides sequelize from Database public interface.
  - Updates table and model names for StakeRequestModel.
  - Removes StakeRequestRepository::build interface for now.
  - Improves StakeRequestRepository::create unit test.
@pgev
Copy link
Contributor Author

pgev commented Jun 20, 2019

This looks very clean 👍

Questions:

  1. Why do we need StakeRequestAttributes? Is it that any class that implement the StakeRequestAttributes interface can be passed in the build and create params?

Yes. StakeRequestAttributers is an interface for an input to create StakeRequest object.

  1. What StakeRequestRepository.build does?

build pattern in sequelize creates an object, which is not yet saved in database model and can be separately (in some other time) saved into database. However, I've decided to remove that for now. We can add it later if needed.

  1. What do you think if we do the following?

    • StakeRequestRepository can extends Model
    • StakeRequestModel can be a simple class that has all the properties (may be some functions to implement business logic). Implements/confirms to the StakeRequestAttributes interface.
    • StakeRequestModel can be passed as params in StakeRequestRepository.build and StakeRequestRepository.create
    • StakeRequestModel is returned from StakeRequestRepository.get function.

In this way there is clear separation of Model objects(related to facilitator) and Repository (sequelize model objects)

In the current design, StakeRequestModel is a sequelize model, which in my understanding represents two things: a database schema model, its init function defines database table schema and database table raw (all find* functions returns Model object).

Currently, for abstracting away from underlying database representation there are StakeRequestAttributes, StakeRequest and StakeRequestRepository classes. I've made some changes after your comment, please, have a look and we could discuss this point one more time. Thx!

@pgev pgev changed the title Draft implementation of stake request model with sequelize Stake request model classes Jun 20, 2019
@pgev pgev changed the title Stake request model classes StakeRequest model (with a help of sequelize) Jun 20, 2019
@abhayks1 abhayks1 self-assigned this Jun 20, 2019
@abhayks1
Copy link
Contributor

Started reviewing 🎸 🚗

Copy link
Contributor

@abhayks1 abhayks1 left a comment

Choose a reason for hiding this comment

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

Really nice work with sequelize integration 🚀 💯
Liked the classes segregation.

Added few suggestions:

  • Database class can create and return singleton sequelize instance. It makes sure there are not too many sequelize db instances.

  • Migrations can be used for creating tables.

  • I feel 🤔 we shouldn't import/load all repositories at once for memory footprint and maintenance. As respositries increase this will not be maintainable . Currently Database class loads all the repositories. We can import/load only those repositories which are needed in a service/process.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/models/Database.ts Outdated Show resolved Hide resolved
src/models/Database.ts Outdated Show resolved Hide resolved
src/models/Database.ts Outdated Show resolved Hide resolved
src/models/StakeRequestRepository.ts Show resolved Hide resolved
Removes an empty StakeRequestRepository::constructor tests file.
Updates unit tests accordingly.
@abhayks1 abhayks1 removed their assignment Jun 20, 2019
@abhayks1 abhayks1 self-assigned this Jun 21, 2019
@abhayks1
Copy link
Contributor

abhayks1 commented Jun 21, 2019

Reviewing 🚋

tests/models/StakeRequestRepository/create.test.ts Outdated Show resolved Hide resolved
tests/models/StakeRequestRepository/get.test.ts Outdated Show resolved Hide resolved
src/models/Database.ts Show resolved Hide resolved
src/models/Database.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@deepesh-kn deepesh-kn left a comment

Choose a reason for hiding this comment

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

LGTM 💯 👍

I have added a few comments.

tests/models/StakeRequestRepository/util.ts Show resolved Hide resolved
src/models/StakeRequestRepository.ts Show resolved Hide resolved
src/models/StakeRequestRepository.ts Show resolved Hide resolved
Copy link
Contributor

@abhayks1 abhayks1 left a comment

Choose a reason for hiding this comment

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

Overall looks good to me 🥇
Added few minor comments on tests.

@abhayks1 abhayks1 removed their assignment Jun 21, 2019
Paruyr Gevorgyan added 2 commits June 21, 2019 12:09
  - Improves documentation for StakeRequestRepository.
  - Enhances error message for StakeRequestRepository::create.
@pgev pgev requested review from abhayks1 and deepesh-kn June 21, 2019 10:55
src/models/Database.ts Outdated Show resolved Hide resolved
@pgev pgev requested a review from deepesh-kn June 21, 2019 13:54
Copy link
Contributor

@deepesh-kn deepesh-kn left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@deepesh-kn deepesh-kn dismissed abhayks1’s stale review June 21, 2019 14:02

Changes are implemented.

@deepesh-kn deepesh-kn merged commit 22f646a into OpenST:master Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement stake requests model class
3 participants