Created
May 14, 2021 09:18
-
-
Save ggallovalle/bee221d7804b56894bd46ab7f671e354 to your computer and use it in GitHub Desktop.
Nestjs new Router Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// router.module.ts | |
const routes: Routes = [ | |
{ | |
path: '/company', | |
module: CompanyModule, | |
children: [ | |
{ | |
path: '/:company/subcompany', | |
module: SubCompanyModule, | |
children: [ | |
{ | |
path: '/:subcompany/development', | |
module: DevelopmentModule, | |
children: [ | |
{ | |
path: '/:development/house', | |
module: HouseModule | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
]; | |
// company.controller.ts | |
@Controller() | |
export class CompanyController { | |
constructor() { | |
} | |
@Get(':company') | |
getCompany(@Param('company') company: string) { | |
return `company/${company}` | |
} | |
} | |
// subcompany.controller.ts | |
import { Controller, Get, Param } from '@nestjs/common'; | |
@Controller() | |
export class SubCompanyController { | |
constructor() { | |
} | |
@Get(':subcompany') | |
getSubCompany( | |
@Param('company') company: string, | |
@Param('subcompany') subcompany: string) { | |
return `company/${company}/subcompany/${subcompany}`; | |
} | |
} | |
// development.controller.ts | |
@Controller() | |
export class DevelopmentController { | |
constructor() { | |
} | |
@Get(':development') | |
getSubCompany( | |
@Param('company') company: string, | |
@Param('subcompany') subcompany: string, | |
@Param('development') development: string, | |
) { | |
return `company/${company}/subcompany/${subcompany}/development/${development}`; | |
} | |
} | |
// house.controller.ts | |
@Controller() | |
export class HouseController { | |
constructor() { | |
} | |
@Get(':house') | |
getSubCompany( | |
@Param('company') company: string, | |
@Param('subcompany') subcompany: string, | |
@Param('development') development: string, | |
@Param('house') house: string | |
) { | |
return `company/${company}/subcompany/${subcompany}/development/${development}/house/${house}`; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment