"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const typeorm_1 = require("typeorm");
const entities_1 = require("../../../entities");
exports.leavePlayGroup = {
    async leavePlayGroup(_, { 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 => {
            let index = boardIdList.indexOf(boardId);
            if (index !== -1) {
                boardIdList.splice(index, 1);
            }
        });
        const boardRepository = typeorm_1.getRepository(entities_1.Board);
        playGroup.boards = await boardRepository.findByIds(boardIdList);
        return await repository.save(playGroup);
    }
};
//# sourceMappingURL=leave-play-group.js.map