Newer
Older
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { Repository } from "typeorm";
import { InjectRepository } from "@nestjs/typeorm";
import { PersonEntity } from './user.entity';
import { UserDTO } from './user.dto';
import { GameEntity } from '../game/game.entity';
import { GameDTO } from '../game/game.dto';
private userRepository: Repository<PersonEntity>,
@InjectRepository(GameEntity)
private gameRepository: Repository<GameEntity>
let user = await this.userRepository.findOne({ where: { name } });
if (user) {
throw new HttpException('User already exists', HttpStatus.BAD_REQUEST);
}
user = await this.userRepository.create(data);
await this.userRepository.save(user);
return user.tokenObject();
}
async login(data: UserDTO) {
const user = await this.userRepository.findOne({ where: { name } });
if (!user || !(await user.comparePassword(password))) {
throw new HttpException('invalid password', HttpStatus.BAD_REQUEST);
} catch (error) {
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
try {
// etsi peli valinnan mukaan ja otetaan käyttäjän rooli kyseisestä pelistä talteen
const role = await this.gameRepository.findOne();
} catch (error) {
return error.message;
}
}
// liitytään factionii
async joinFaction(game: GameDTO, data: UserDTO): Promise<boolean> {
try {
// tarkistetaan factionin salasana
return true;
} catch (error) {
return error;
}
}