Closed cecilia-sanare closed 5 years ago
Your feature request has been fulfilled. OvernightJS now supports both nested controllers with the @Children
decorator and adding options to controllers with the @ClassOptions
decorator. Here's an example:
import { Controller, Get, Children, ClassOptions } from '@overnightjs/core';
import { Logger } from '@overnightjs/logger';
import { Request, Response } from 'express';
import { OK } from 'http-status-codes';
import { GrandChild1Controller } from './grandchildren/GrandChild1Controller';
import { GrandChild2Controller } from './grandchildren/GrandChild2Controller';
import { GrandChild3Controller } from './grandchildren/GrandChild3Controller';
@Controller('child-b1/:name')
@ClassOptions({mergeParams: true})
@Children([
new GrandChild1Controller(),
new GrandChild2Controller(),
new GrandChild3Controller(),
])
export class ChildB1Controller {
@Get()
private get(req: Request, res: Response) {
const message = 'Hi I\'m the child B1 controller';
Logger.Info(message);
Logger.Info(req.params, true);
return res.status(OK).json({message});
}
}
Description
Currently it's impossible to specify parameters at the controller-level.
Which would be useful for routes nested under other controllers.
Example
Workaround