56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import {
|
|
Body,
|
|
ClassSerializerInterceptor,
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
UseGuards,
|
|
UseInterceptors,
|
|
} from '@nestjs/common';
|
|
import {
|
|
ApiBadRequestResponse,
|
|
ApiBearerAuth,
|
|
ApiBody,
|
|
ApiOkResponse,
|
|
ApiOperation,
|
|
ApiTags,
|
|
} from '@nestjs/swagger';
|
|
import { User } from 'src/objects/user/user.entity';
|
|
import { LoggedInUser } from 'src/shared/decorators/user.decorator';
|
|
import { AuthGuard } from 'src/shared/guards/auth.guard';
|
|
import { AppUserService } from './app-user.service';
|
|
import { UserLoginResponseDto } from './dto/user-login-response.dto';
|
|
import { UserLoginDto } from './dto/user-login.dto';
|
|
|
|
@ApiTags('users')
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
@Controller({
|
|
path: 'user',
|
|
})
|
|
export class AppUserController {
|
|
constructor(private readonly service: AppUserService) {}
|
|
|
|
@Post('login')
|
|
@ApiBody({ type: UserLoginDto })
|
|
@ApiOperation({ summary: 'Log in using email and password' })
|
|
@ApiBadRequestResponse()
|
|
@ApiOkResponse({ type: UserLoginResponseDto })
|
|
async userDoLogin(@Body() body: UserLoginDto) {
|
|
return this.service.login(body);
|
|
}
|
|
|
|
@Get()
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Get logged in user' })
|
|
@ApiBearerAuth('Bearer auth')
|
|
async userGetInfo(@LoggedInUser() user: User) {
|
|
return {
|
|
name: user.name,
|
|
email: user.email,
|
|
emailVerified: user.emailVerified,
|
|
picture: user.picture,
|
|
updatedAt: user.updatedAt,
|
|
};
|
|
}
|
|
}
|