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-31 23:42:48 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6fd1f28bf802fc79b18820d145d34a388b23cd2d
6fd1f28b
1 parent
30c54866
remove unnecessary file
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
84 deletions
back/src/api/Message/newMessage/newMessage.graphql
back/src/api/Message/newMessage/newMessage.js
back/src/api/Message/newMessage/newMessage.graphql
deleted
100644 → 0
View file @
30c5486
type Mutation {
newMessage(receiverEmail: String, message: String!, roomId: Int): Message!
}
back/src/api/Message/newMessage/newMessage.js
deleted
100644 → 0
View file @
30c5486
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
;
},
},
};
Please
register
or
login
to post a comment