100 lines
2.1 KiB
TypeScript
100 lines
2.1 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Put,
|
|
Param,
|
|
Delete,
|
|
ParseUUIDPipe,
|
|
HttpStatus,
|
|
Query,
|
|
Request,
|
|
} from '@nestjs/common';
|
|
import { UsersService } from './users.service';
|
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
import { UpdateUserDto } from './dto/update-user.dto';
|
|
import { Public } from '../auth/public.decorator';
|
|
|
|
@Controller({
|
|
path: 'users',
|
|
version: '1',
|
|
})
|
|
export class UsersController {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@Post()
|
|
async create(@Request() req, @Body() createUserDto: CreateUserDto) {
|
|
return {
|
|
data: await this.usersService.create(createUserDto, req.user),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Public()
|
|
@Get()
|
|
async findAll(@Query('page') page: number) {
|
|
const [data, count] = await this.usersService.findAll(page);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('find-by-supperior')
|
|
async findBySuperrior(@Request() req, @Query('page') page: number) {
|
|
return {
|
|
data: await this.usersService.findBySuperrior(req.user.userId, page),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('find-by-roles/:id')
|
|
async findByRoles(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Query('page') page: number,
|
|
) {
|
|
return {
|
|
data: await this.usersService.findByRoles(id, page),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get(':id')
|
|
async findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return {
|
|
data: await this.usersService.findOne(id),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Put(':id')
|
|
async update(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() updateUserDto: UpdateUserDto,
|
|
) {
|
|
return {
|
|
data: await this.usersService.update(id, updateUserDto),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Delete(':id')
|
|
async remove(@Param('id', ParseUUIDPipe) id: string) {
|
|
await this.usersService.remove(id);
|
|
|
|
return {
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
}
|