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-01 13:21:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0f264b1880e09871c864d76f8f8a523694a008d1
0f264b18
1 parent
fe5e4e3e
update newMessage resolver
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
back/src/api/Chat/newMessage/newMessage.js
back/src/api/Chat/newMessage/newMessage.js
View file @
0f264b1
import
{
isAuthenticated
,
prisma
}
from
"../../../utils"
;
import
{
NEW_MESSAGE_TOPIC
}
from
"../../../topics"
;
import
{
ONE_TO_ONE_MESSAGE
}
from
"../../../topics"
;
export
default
{
Mutation
:
{
newMessage
:
async
(
_
,
args
,
{
request
,
pubsub
})
=>
{
//
isAuthenticated(request);
isAuthenticated
(
request
);
const
{
user
}
=
request
;
const
{
receiverId
,
message
,
roomId
}
=
args
;
let
room
;
let
room
=
await
prisma
.
room
.
findOne
({
where
:
{
id
:
roomId
,
},
});
room
=
await
prisma
.
room
.
update
({
where
:
{
id
:
roomId
,
},
data
:
{
participants
:
{
connect
:
[{
id
:
user
.
id
},
{
id
:
receiverId
}],
},
},
});
// 방이 없는 경우
if
(
room
Id
===
undefined
)
{
if
(
room
===
undefined
||
room
===
null
)
{
// 보내는 사람과 받는 사람이 다른 경우
if
(
user
.
id
!==
receiverId
)
{
room
=
await
prisma
.
room
.
create
({
...
...
@@ -29,20 +43,11 @@ export default {
},
});
}
}
else
{
// 방이 있는 경우
room
=
await
prisma
.
room
.
findOne
({
where
:
{
id
:
roomId
,
},
});
}
if
(
!
room
)
{
throw
new
Error
(
"There is no room"
);
}
// 메시지 생성부분. (지금은 1명 밖에 안들어간 구조.)
const
newMessage
=
await
prisma
.
message
.
create
({
const
subMessage
=
await
prisma
.
message
.
create
({
data
:
{
text
:
message
,
to
:
{
...
...
@@ -62,8 +67,9 @@ export default {
},
},
});
pubsub
.
publish
(
NEW_MESSAGE_TOPIC
,
{
newMessage
});
return
newMessage
;
console
.
log
(
subMessage
);
pubsub
.
publish
(
ONE_TO_ONE_MESSAGE
,
subMessage
);
return
subMessage
;
},
},
};
...
...
Please
register
or
login
to post a comment