-
Notifications
You must be signed in to change notification settings - Fork 36
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
Version in routes #29
Comments
it the obvious result as any expressjs supports routes alias as an array so we can use app.get(['/user/:id', '/profile/:id'], (req, res) => { ... }); as nest-router uses the build-in we cannot provide it as an array. you can create another module with the same name and post-fix it with v2 or whatever, to be clear i'll make it as an example: we have module ...
@Controller('/payment')
export class UserPayment {
@Get(':id')
async getUserPayments(@Parm('id') userId: number) {
...
// some complex sql calls
}
...
// another methods
} ...
@Module({
controllers: [UserPayment]
})
export class Users {} then we have updated our api and now we have api v2 we will create another module ...
@Controller('/payment')
export class UserPaymentV2 extends UserPayment {
@Get(':id')
async getUserPayments(@Parm('id') userId: number) {
...
// some complex sql calls
// with update for v2
}
...
// another methods from extended class
} ...
@Module({
controllers: [UserPaymentV2]
})
export class UsersV2 {} then in our routes const routes: Routes = [
{
path: 'v1',
children: [{ path: 'users', module: Users }],
},
{
path: 'v2',
children: [{ path: 'users', module: UsersV2 }],
},
];
|
@shekohex Do you think this is a good idea? Let say we will have 3 versions. In the user folder, there will be 3 files for each user.module.ts and user.controller.ts |
@vahidvdn so you have 3 versions of the same Controller? |
@shekohex Thanks for the point. |
Did you tried to use the same Module, but with 3 Different Controllers? Every one of these extends the previous one with new changes and with a new route in the Is that ok? |
@shekohex No, that's not. In your example:
In v2 path, you mentioned UsersV2 module. So, as I understand we can't have only one module. Am I right? |
Yes, any module will only have one version, but as many Controllers you wish, so I guess you could instead of using this package you could add the versions to the Controllers itself. If you don't need to versioning based on the modules. |
When I want to do multiple versions on my routes, and I reuse a controller for certain version, it only takes the latest version.
gives
So I miss, the v1 mapping
The text was updated successfully, but these errors were encountered: