Newer
Older
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { GameEntity, FactionEntity } from './game.entity';
import { FactionDTO, GameDTO } from './game.dto';
@Injectable()
export class GameService {
constructor(
@InjectRepository(GameEntity)
private gameRepository: Repository<GameEntity>,
@InjectRepository(FactionEntity)
private factionRepository: Repository<FactionEntity>,
// create a new game
async createNewGame(
personId: string,
gameData: GameDTO,
factions: FactionDTO[],
) {
const game = await this.gameRepository.create({
...gameData,
factions: factions,
});
await this.gameRepository.insert(game);
const gameid = await this.gameRepository.findOne({ where: { name: gameData.name } })
factions.map(async faction => {
let name = await this.factionRepository.create({
...faction,
game: gameid
});
await this.factionRepository.insert(name);
async listGames() {
const games = await this.gameRepository.find({ relations: ['factions'] });
return games.map(game => {