-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
chore: Abstract module service #6188
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
@srindom @olivermrbl could I have your opinion? Also, it doesn't seem a lot, but if I apply that to all module the footprint will be reduced by a lot. Also, it means that now all read and delete, soft, restore method are auto generated, meaning you can focus on create, update and other custom method which in most cases are the one having most of the business logic |
This is amazing! |
LFG!! 🚀 🚀 Really great |
I ve reached one limitation of typescript microsoft/TypeScript#48125 (comment) if anybody want to pitch in 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Suggest that we merge and start using it ASAP, fixes and adjustments can follow in separate PRs.
@olivermrbl any reason this pr is mentioned in the dashboard pr? |
No that was by mistake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 🔥 🔥 🔥
@olivermrbl @srindom ready to be merged as soon as the pipeline is green, please seb have a look to the changes I ve done on the customer module though. I had to change quite a few things, I ve put some todos here and there in different modules for naming and stuff, they are not specific but later on we can do a cleanup round |
@@ -183,7 +183,7 @@ describe("Currency Service", () => { | |||
error = e | |||
} | |||
|
|||
expect(error.message).toEqual('"currencyCode" must be defined') | |||
expect(error.message).toEqual("currency - code must be defined") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: How are these error messages generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find them in the internal service factory. But before they where trying to provide the name of the expected argument except that it doesn't work anymore, so now it shows the primary key(s) missing
lowerCaseFirst(model.name) + upperCaseFirst(primaryKeys[0]) | ||
}"` | ||
: `${lowerCaseFirst(model.name)} ${primaryKeys.join(", ")}` | ||
? `"${lowerCaseFirst(model.name) + " - " + primaryKeys[0]}"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought(non-blocking): Can we do better than this?
Ideally, we have something like:
currencyCode
priceListId
moneyAmountId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it makes you think you need to provide { currencyCode } when we expect { code } ?
…a into chore/improve-modules-dev
What
The above methods are created for the main model and also for each other models for which a config is provided
all method such as list, listAndCount, delete, softDelete and restore are pluralized with the model it refers to
Migration
Usage
Module
The module service can now extend the
ModulesSdkUtils.abstractModuleServiceFactory
which returns a class with the default implementation for each method and each model following the standard naming convention mentioned above.This factory have 3 template arguments being the container, the main model DTO and an object representing the other model with a config object that contains at list the DTO and optionally a singular and plural property in case it needs to be set manually. It looks like the following:
In the above, the singular and plural can be inferred as there is no tricky naming. Also, the default implementation does not remove the fact that you need to provides all the overloads etc in your module service interface. The above will provide a default implementation following the interface
AbstractModuleService
which is also auto generated, hence you will have the following methods available:for the main model
for the other models
Internal module service
The internal module service can now extend
ModulesSdkUtils.internalModuleServiceFactory
which takes only one template argument which is the container type.All internal services provides a default implementation for all retrieve, list, listAndCount, create, update, delete, softDelete, restore methods which follow the following interface
ModulesSdkTypes.InternalModuleService
:When a service is auto generated you can use that interface to type your class property representing the expected internal service.
Repositories
The repositories can now extend
DALUtils.mikroOrmBaseRepositoryFactory
which takes one template argument being the entity or the template entity and provides all the default implementation. If the repository is auto generated you can type it using theRepositoryService
interface. Here is the new interface typings.