Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-05-06 00:17:20 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
392a3dc5d15099e4766391edd41f0d8dee2daede
392a3dc5
1 parent
21c71213
update newMessage
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
19 deletions
back/src/api/Chat/newMessage/newMessage.graphql
back/src/api/Chat/newMessage/newMessage.js
back/src/api/Chat/newMessage/newMessage.graphql
View file @
392a3dc
type Mutation {
newMessage(receiver
Id: Int
, message: String!, roomId: Int): Message!
newMessage(receiver
Email: String
, message: String!, roomId: Int): Message!
}
...
...
back/src/api/Chat/newMessage/newMessage.js
View file @
392a3dc
import
{
isAuthenticated
,
prisma
}
from
"../../../utils"
;
import
{
ONE_TO_ONE_MESSAGE
}
from
"../../../topics"
;
// newMessage 에서는 1:1, 1:n 메시지 방만 가정하고 있음
// 나머지 랜덤채팅은 아직 구상중 (5/4) 기준
export
default
{
Mutation
:
{
newMessage
:
async
(
_
,
args
,
{
request
,
pubsub
})
=>
{
isAuthenticated
(
request
);
const
{
user
}
=
request
;
const
{
receiver
Id
,
message
,
roomId
}
=
args
;
let
room
=
await
prisma
.
room
.
findOne
({
const
{
receiver
Email
,
message
,
roomId
}
=
args
;
const
receiver
=
await
prisma
.
user
.
findOne
({
where
:
{
id
:
roomId
,
email
:
receiverEmail
,
},
});
room
=
await
prisma
.
room
.
update
({
let
room
=
await
prisma
.
room
.
findOne
({
where
:
{
id
:
roomId
,
},
data
:
{
participants
:
{
connect
:
[{
id
:
user
.
id
},
{
id
:
receiverId
}],
},
},
});
// 방이 없는 경우
if
(
room
===
undefined
||
room
===
null
)
{
// 보내는 사람과 받는 사람이 다른 경우
if
(
user
.
id
!==
receiver
I
d
)
{
if
(
user
.
id
!==
receiver
.
i
d
)
{
room
=
await
prisma
.
room
.
create
({
data
:
{
participants
:
{
connect
:
[{
id
:
receiver
I
d
},
{
id
:
user
.
id
}],
connect
:
[{
id
:
receiver
.
i
d
},
{
id
:
user
.
id
}],
},
},
});
...
...
@@ -43,23 +42,32 @@ export default {
},
});
}
}
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
toUser
=
await
prisma
.
user
.
findOne
({
where
:
{
id
:
receiverId
,
},
});
const
subMessage
=
await
prisma
.
message
.
create
({
data
:
{
text
:
message
,
to
:
{
connect
:
[{
id
:
toUser
.
id
}]
,
connect
:
{
id
:
receiver
.
id
}
,
},
from
:
{
connect
:
[{
id
:
user
.
id
}]
,
connect
:
{
id
:
user
.
id
}
,
},
room
:
{
connect
:
{
...
...
Please
register
or
login
to post a comment