switch to nx monorepo

This commit is contained in:
Philipinho
2024-01-09 18:58:26 +01:00
parent e1bb2632b8
commit 093e634c0b
273 changed files with 11419 additions and 31 deletions

View File

@ -0,0 +1,58 @@
import {
Controller,
Get,
UseGuards,
HttpCode,
HttpStatus,
Req,
UnauthorizedException,
Post,
Body,
} from '@nestjs/common';
import { UserService } from './user.service';
import { JwtGuard } from '../auth/guards/JwtGuard';
import { FastifyRequest } from 'fastify';
import { User } from './entities/user.entity';
import { Workspace } from '../workspace/entities/workspace.entity';
import { UpdateUserDto } from './dto/update-user.dto';
@UseGuards(JwtGuard)
@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}
@HttpCode(HttpStatus.OK)
@Get('me')
async getUser(@Req() req: FastifyRequest) {
const jwtPayload = req['user'];
const user: User = await this.userService.findById(jwtPayload.sub);
if (!user) {
throw new UnauthorizedException('Invalid user');
}
return { user };
}
@HttpCode(HttpStatus.OK)
@Get('info')
async getUserInfo(@Req() req: FastifyRequest) {
const jwtPayload = req['user'];
const data: { workspace: Workspace; user: User } =
await this.userService.getUserInstance(jwtPayload.sub);
return data;
}
@HttpCode(HttpStatus.OK)
@Post('update')
async updateUser(
@Req() req: FastifyRequest,
@Body() updateUserDto: UpdateUserDto,
) {
const jwtPayload = req['user'];
return this.userService.update(jwtPayload.sub, updateUserDto);
}
}