createRoom.js 907 Bytes
import { prisma } from "../../../utils";

export default {
  Mutation: {
    createRoom: async (_, args) => {
      const { participantsId, categories, name } = args;
      let newRoom, participantId;
      if (participantsId !== undefined) {
        newRoom = await prisma.room.create({
          data: {
            participants: {
              connect: {
                id: (participantId = participantsId.forEach(
                  (cur, _, __) => cur
                )),
              },
            },
            name,
          },
        });
      }
      if (categories !== undefined) {
        newRoom = await prisma.room.create({
          data: {
            categories: {
              connect: {
                id: (category = categories.forEach((cur, _, __) => cur)),
              },
            },
            name,
          },
        });
      }
      return newRoom;
    },
  },
};