Skip to content

Commit

Permalink
ADD: nested routes for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
mogaming217 committed Feb 5, 2021
1 parent 44b1c27 commit 0292db2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/users/posts/posts.controller.spec.ts
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PostsController } from './posts.controller';

describe('PostsController', () => {
let controller: PostsController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PostsController],
}).compile();

controller = module.get<PostsController>(PostsController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
9 changes: 9 additions & 0 deletions src/users/posts/posts.controller.ts
@@ -0,0 +1,9 @@
import { Controller, Get, Param } from '@nestjs/common';

@Controller('users/:userID/posts')
export class PostsController {
@Get()
findAll(@Param('userID') userID: string) {
return userID;
}
}
7 changes: 7 additions & 0 deletions src/users/posts/posts.module.ts
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { PostsController } from './posts.controller';

@Module({
controllers: [PostsController],
})
export class PostsModule {}
2 changes: 2 additions & 0 deletions src/users/users.module.ts
@@ -1,9 +1,11 @@
import { Module } from '@nestjs/common';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
import { PostsModule } from './posts/posts.module';

@Module({
controllers: [UsersController],
providers: [UsersService],
imports: [PostsModule],
})
export class UsersModule {}

0 comments on commit 0292db2

Please sign in to comment.