mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-18 05:09:29 +00:00
add auth
This commit is contained in:
47
src/modules/users/api/users.controller.ts
Normal file
47
src/modules/users/api/users.controller.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
NotFoundException,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { UsersService } from '../services/users.service';
|
||||
import { CreateUserDto } from '../dto/create-user.dto';
|
||||
import { Pagination } from '../../../infrastructure/common/pagination.service';
|
||||
import { BaseAuthGuard } from '../../auth/guards/base-auth.guard';
|
||||
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor(private usersService: UsersService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Query() query) {
|
||||
const { page, pageSize, searchNameTerm } =
|
||||
Pagination.getPaginationData(query);
|
||||
const users = await this.usersService.getUsers(
|
||||
page,
|
||||
pageSize,
|
||||
searchNameTerm,
|
||||
);
|
||||
if (!users) throw new NotFoundException('Users not found');
|
||||
return users;
|
||||
}
|
||||
//@UseGuards(BaseAuthGuard)
|
||||
@Post()
|
||||
async create(@Body() createUserDto: CreateUserDto) {
|
||||
return await this.usersService.createUser(
|
||||
createUserDto.login,
|
||||
createUserDto.password,
|
||||
createUserDto.email,
|
||||
);
|
||||
}
|
||||
@UseGuards(BaseAuthGuard)
|
||||
@Delete(':id')
|
||||
async remove(@Param('id') id: string) {
|
||||
return await this.usersService.deleteUserById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user