-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user routes, enable auth globally
- Loading branch information
1 parent
113658a
commit 2e3d439
Showing
10 changed files
with
170 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { SetMetadata } from '@nestjs/common'; | ||
|
||
export const IS_NO_AUTH_KEY = 'isNoAuth'; | ||
export const NoAuth = () => SetMetadata(IS_NO_AUTH_KEY, true); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
Controller, | ||
Body, | ||
Param, | ||
Post, | ||
Get, | ||
Patch, | ||
Delete, | ||
} from '@nestjs/common'; | ||
import { ApiResponse, ApiTags, ApiBearerAuth } from '@nestjs/swagger'; | ||
import { UserService } from './user.service'; | ||
import { SignupDto } from '../auth/dto/signup.dto'; | ||
import { IUser } from './user.interface'; | ||
import { UpdateUserDto } from './user.dto'; | ||
|
||
@Controller('api/users') | ||
@ApiTags('users') | ||
export class UserController { | ||
constructor(private readonly userService: UserService) {} | ||
|
||
@Post() | ||
@ApiBearerAuth() | ||
@ApiResponse({ status: 201, description: 'New User Created' }) | ||
@ApiResponse({ status: 400, description: 'Bad Request' }) | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
async create(@Body() signupDto: SignupDto): Promise<IUser> { | ||
return this.userService.create(signupDto); | ||
} | ||
|
||
@Get() | ||
@ApiBearerAuth() | ||
@ApiResponse({ status: 200, description: 'All Users' }) | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
async findAll(): Promise<Array<IUser>> { | ||
return this.userService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
@ApiBearerAuth() | ||
@ApiResponse({ status: 200, description: 'User For Given ID' }) | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
@ApiResponse({ status: 404, description: 'Not Found' }) | ||
async findOne(@Param('id') id: string): Promise<IUser> { | ||
return this.userService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
@ApiBearerAuth() | ||
@ApiResponse({ status: 200, description: 'Successful Update' }) | ||
@ApiResponse({ status: 400, description: 'Bad Request' }) | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
@ApiResponse({ status: 403, description: 'Forbidden Resource' }) | ||
async update( | ||
@Param('id') id: string, | ||
@Body() updateUserDto: UpdateUserDto, | ||
): Promise<any> { | ||
return this.userService.update(+id, updateUserDto); | ||
} | ||
|
||
@Delete(':id') | ||
@ApiBearerAuth() | ||
@ApiResponse({ status: 200, description: 'Successful Delete' }) | ||
@ApiResponse({ status: 400, description: 'Bad Request' }) | ||
@ApiResponse({ status: 401, description: 'Unauthorized' }) | ||
@ApiResponse({ status: 403, description: 'Forbidden Resource' }) | ||
async delete(@Param('id') id: number): Promise<any> { | ||
return this.userService.delete(+id); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { Allow } from 'class-validator'; | ||
|
||
export class UpdateUserDto { | ||
@ApiPropertyOptional() | ||
@Allow() | ||
firstName: string; | ||
|
||
@ApiPropertyOptional() | ||
@Allow() | ||
lastName: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { User } from './user.entity'; | ||
import { UsersService } from './user.service'; | ||
import { UserController } from './user.controller'; | ||
import { UserService } from './user.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([User])], | ||
exports: [UsersService], | ||
providers: [UsersService], | ||
controllers: [UserController], | ||
providers: [UserService], | ||
exports: [UserService], | ||
}) | ||
export class UserModule {} |
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