import { Body , Controller , Post , Get } from '@nestjs/common' ; import { UserService } from '../shared/user.service' ; import { Payload } from '../types/payload' ; import { LoginDTO , RegisterDTO } from './auth.dto' ; import { AuthService } from './auth.service' ; @ Controller ( 'auth' ) export class AuthController { constructor ( private userService , private authService ) { } @ Post ( 'login' ) async login ( @ Body ( ) userDTO ) { const user = await this . userService . findByLogin ( userDTO ) ; const payload = { username : user . username , seller : user . seller , } ; const token = await this . authService . signPayload ( payload ) ; return { user , token } ; } @ Post ( 'register' ) async register ( @ Body ( ) userDTO ) { const user = await this . userService . create ( userDTO ) ; const payload = { username : user . username , seller : user . seller , } ; const token = await this . authService . signPayload ( payload ) ; return { user , token } ; } }