@Get('/:id')
example(@Param('id') id: string)
@Post()
example(@Body() body: any)
if(!message)
{
throw new NotFoundException('message not found');
}
messagesRepo: MessagesRepository;
constructor() {
this.messagesRepo = new MessagesRepository();
}
// Service는 Repository가 있어야 ( Dependency ) 사용가능
에서
messagesRepo: MessagesRepository;
constructor(messagesRepo: MessagesRepository) {
this.messagesRepo = messagesRepo;
}
와 같이
@Injectable()
export class MessagesRepository
@Module({
controllers: [MessagesController],
providers: [MessagesService, MessagesRepository]
})
constructor(private powerService: PowerService)
와 같이 사용 가능.
async function bootstrap() {
const app = await NestFactory.create(ComputerModule);
await app.listen(3000);
}
bootstrap();
@Module({
providers: [PowerService],
exports: [PowerService]
})
export class PowerModule {}
@Module({
providers: [ComputerService],
imports: [PowerModule]
})
export class ComputerModule {}
@Injectable()
export class ComputerService {
constructor(private powerService: PowerService) {}
}
@Transform(({obj}) => obj.user.id)
@Expose()
userId: number;
export class CurrentUserMiddleware implements NestMiddleware {
async use(req: Request, res: Response, next: NextFunction) {
}
}