sdy

remove unnecessary file

type Mutation {
newMessage(receiverEmail: String, message: String!, roomId: Int): Message!
}
import { isAuthenticated, prisma } from "../../../utils";
import { ONE_TO_ONE_MESSAGE } from "../../../topics";
export default {
Mutation: {
newMessage: async (_, args, { request, pubsub }) => {
isAuthenticated(request);
const { user } = request;
const { receiverEmail, message, roomId } = args;
const receiver = await prisma.user.findOne({
where: {
email: receiverEmail,
},
});
let room = await prisma.room.findOne({
where: {
id: roomId,
},
});
// 방이 없는 경우
if (room === undefined || room === null) {
// 보내는 사람과 받는 사람이 다른 경우
if (user.id !== receiver.id) {
room = await prisma.room.create({
data: {
participants: {
connect: [{ id: receiver.id }, { id: user.id }],
},
},
});
} else {
// 자기 자신에게 보내는 경우
room = await prisma.room.create({
data: {
participants: {
connect: [{ id: user.id }],
},
},
});
}
} else {
// 방이 원래 있던 경우 업데이트
room = await prisma.room.update({
where: {
id: roomId,
},
data: {
participants: {
connect: [{ id: user.id }, { id: receiver.id }],
},
},
});
}
if (!room) {
throw new Error("There is no room");
}
const subMessage = await prisma.message.create({
data: {
text: message,
to: {
connect: { id: receiver.id },
},
from: {
connect: { id: user.id },
},
room: {
connect: {
id: room.id,
},
},
},
});
pubsub.publish(ONE_TO_ONE_MESSAGE, subMessage);
return subMessage;
},
},
};