"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const typeorm_1 = require("typeorm");
const entities_1 = require("../../../entities");
exports.joinPlayGroup = {
    async joinPlayGroup(_, { id, boardIds }) {
        const repository = typeorm_1.getRepository(entities_1.PlayGroup);
        const playGroup = await repository.findOne({ id }, {
            relations: ['boards']
        });
        const boardIdList = playGroup.boards.map(board => board.id);
        boardIds.forEach(boardId => {
            if (boardIdList.indexOf(boardId) == -1) {
                boardIdList.push(boardId);
            }
        });
        const boardRepository = typeorm_1.getRepository(entities_1.Board);
        playGroup.boards = await boardRepository.findByIds(boardIdList);
        return await repository.save(playGroup);
    }
};
//# sourceMappingURL=join-play-group.js.map