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-04-29 20:46:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c803530880b69f9ca94e8c9acc4733929c639132
c8035308
1 parent
97dfaaeb
create newMessage
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
back/src/api/Chat/newMessage/newMessage.graphql
back/src/api/Chat/newMessage/newMessage.js
back/src/api/Chat/newMessage/newMessage.graphql
0 → 100644
View file @
c803530
type Mutation {
newMessage(receiverId: String!, message: String!, roomId: String!): Message!
}
back/src/api/Chat/newMessage/newMessage.js
0 → 100644
View file @
c803530
import
{
isAuthenticated
,
prisma
}
from
"../../../utils"
;
import
{
NEW_MESSAGE_TOPIC
}
from
"../../../topics"
;
export
default
{
Mutation
:
{
newMessage
:
async
(
_
,
args
,
{
request
,
pubsub
})
=>
{
// isAuthenticated(request);
const
{
user
}
=
request
;
const
{
receiverId
,
message
,
roomId
}
=
args
;
let
room
;
// 방이 없는 경우
if
(
roomId
===
undefined
)
{
// 보내는 사람과 받는 사람이 다른 경우
if
(
user
.
id
!==
receiverId
)
{
room
=
await
prisma
.
room
.
create
({
data
:
{
participants
:
{
connect
:
[{
id
:
receiverId
},
{
id
:
user
.
id
}],
},
},
});
}
else
{
// 자기 자신에게 보내는 경우
room
=
await
prisma
.
room
.
create
({
data
:
{
participants
:
{
connect
:
[{
id
:
user
.
id
}],
},
},
});
}
}
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
({
data
:
{
text
:
message
,
to
:
{
connect
:
{
id
:
receiverId
,
},
},
from
:
{
connect
:
{
id
:
user
.
id
,
},
},
room
:
{
connect
:
{
id
:
room
.
id
,
},
},
},
});
pubsub
.
publish
(
NEW_MESSAGE_TOPIC
,
{
newMessage
});
return
newMessage
;
},
},
};
Please
register
or
login
to post a comment