Showing
1 changed file
with
45 additions
and
0 deletions
1 | +import { prisma, isAuthenticated } from "../../../utils"; | ||
2 | + | ||
3 | +export default () => { | ||
4 | + Mutation: { | ||
5 | + wholeMessage: async (_, args, { request }) => { | ||
6 | + isAuthenticated(request); | ||
7 | + const { user } = request; | ||
8 | + const { message, roomId } = args; | ||
9 | + | ||
10 | + let room = await prisma.room.findOne({ | ||
11 | + where: { | ||
12 | + id: roomId, | ||
13 | + }, | ||
14 | + }); | ||
15 | + | ||
16 | + let messageObj = await prisma.message.create({ | ||
17 | + data: { | ||
18 | + text: message, | ||
19 | + sender: { | ||
20 | + connect: { | ||
21 | + id: user.id, | ||
22 | + }, | ||
23 | + }, | ||
24 | + }, | ||
25 | + }); | ||
26 | + | ||
27 | + if (room !== undefined || room !== null) { | ||
28 | + // 방이 존재하는 경우 | ||
29 | + room = await prisma.room.update({ | ||
30 | + where: { | ||
31 | + id: roomId, | ||
32 | + }, | ||
33 | + data: { | ||
34 | + messages: { | ||
35 | + connect: { | ||
36 | + id: messageObj.id, | ||
37 | + }, | ||
38 | + }, | ||
39 | + }, | ||
40 | + }); | ||
41 | + } | ||
42 | + return messageObj; | ||
43 | + }; | ||
44 | + } | ||
45 | +}; |
-
Please register or login to post a comment