44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
|
|
/* eslint-disable class-methods-use-this */
|
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
import { UsersService } from './users.service';
|
|
import { Body, Controller, Delete, Get, Param, Post, Req, Res } from '@nestjs/common';
|
|
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
import { env } from 'src/config/env';
|
|
import { User } from 'src/schemas/user.schema';
|
|
|
|
@Controller()
|
|
export class UsersController {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@Get('/get-user')
|
|
async getUser(@Req() req: FastifyRequest, @Res() reply: FastifyReply) {
|
|
const token = req.cookies[env.COOKIE_TOKEN_NAME];
|
|
|
|
const user = await this.usersService.getUser(token);
|
|
|
|
return reply.send(user);
|
|
}
|
|
|
|
@Post('/users/create-user')
|
|
async create(@Body() createUserDto: CreateUserDto) {
|
|
return this.usersService.create(createUserDto);
|
|
}
|
|
|
|
@Get('/users')
|
|
async findAll() {
|
|
return this.usersService.findAll();
|
|
}
|
|
|
|
@Delete('/users/delete/:username')
|
|
async delete(@Param('username') username: string) {
|
|
return this.usersService.delete(username);
|
|
}
|
|
|
|
@Post('/users/check')
|
|
async check(@Body() user: User) {
|
|
return this.usersService.check(user);
|
|
}
|
|
}
|