import { Injectable } from '@nestjs/common' ; import { InjectRepository } from '@nestjs/typeorm' ; import { Repository } from 'typeorm' ; import { User } from '../../../typeorm' ; import { UserDetails } from '../../../utils/types' ; import { AuthenticationProvider } from './auth' ; @ Injectable ( ) export class AuthService implements AuthenticationProvider { constructor ( @ InjectRepository ( User ) private userRepo ) { } async validateUser ( details ) { const { discordId } = details ; const user = await this . userRepo . findOne ( { discordId } ) ; if ( user ) { await this . userRepo . update ( { discordId } , details ) ; console . log ( 'Updated' ) ; return user ; } return this . createUser ( details ) ; } createUser ( details ) { const user = this . userRepo . create ( details ) ; return this . userRepo . save ( user ) ; } findUser ( discordId ) { return this . userRepo . findOne ( { discordId } ) ; } }