Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
When Meet - Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem2023-2
When Meet - Backend
Commits
a1666477
Commit
a1666477
authored
1 year ago
by
Wo-ogie
Browse files
Options
Downloads
Patches
Plain Diff
feat: 참가자 존재 여부 확인하기 API 구현
parent
3a5e03ab
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
controllers/participant.js
+47
-19
47 additions, 19 deletions
controllers/participant.js
errors/participantErrors.js
+7
-0
7 additions, 0 deletions
errors/participantErrors.js
routes/participant.js
+6
-1
6 additions, 1 deletion
routes/participant.js
with
60 additions
and
20 deletions
controllers/participant.js
+
47
−
19
View file @
a1666477
const
bcrypt
=
require
(
'
bcrypt
'
);
const
bcrypt
=
require
(
'
bcrypt
'
);
const
{
Participant
}
=
require
(
'
../models
'
);
const
{
createPasswordIsNullError
}
=
require
(
'
../errors/meetingErrors
'
);
const
{
createPasswordIsNullError
}
=
require
(
'
../errors/meetingErrors
'
);
const
{
createParticipantIsAlreadyExistError
,
}
=
require
(
'
../errors/participantErrors
'
);
const
ParticipantResponse
=
require
(
'
../dto/response/participantResponse
'
);
const
ParticipantResponse
=
require
(
'
../dto/response/participantResponse
'
);
const
{
Participant
}
=
require
(
'
../models
'
);
const
HASHING_ROUND
=
12
;
const
HASHING_ROUND
=
12
;
async
function
createParticipant
(
name
,
password
,
email
,
meetingId
)
{
return
Participant
.
create
({
name
,
password
,
email
,
MeetingId
:
meetingId
,
});
}
async
function
findParticipantByMeetingIdAndName
(
meetingId
,
name
)
{
return
Participant
.
findOne
({
where
:
{
MeetingId
:
meetingId
,
name
,
},
});
}
async
function
encryptPassword
(
password
,
next
)
{
async
function
encryptPassword
(
password
,
next
)
{
if
(
!
password
)
{
if
(
!
password
)
{
return
next
(
createPasswordIsNullError
());
return
next
(
createPasswordIsNullError
());
...
@@ -18,24 +39,17 @@ async function encryptPassword(password, next) {
...
@@ -18,24 +39,17 @@ async function encryptPassword(password, next) {
}
}
exports
.
createParticipant
=
async
(
req
,
res
,
next
)
=>
{
exports
.
createParticipant
=
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
req
.
params
);
const
{
meetingId
}
=
req
.
params
;
const
{
meetingId
}
=
req
.
params
;
const
reqName
=
req
.
body
.
name
;
const
reqName
=
req
.
body
.
name
;
const
reqPassword
=
req
.
body
.
password
||
null
;
const
reqPassword
=
req
.
body
.
password
||
null
;
const
reqEmail
=
req
.
body
.
email
||
null
;
const
reqEmail
=
req
.
body
.
email
||
null
;
console
.
log
(
meetingId
);
console
.
log
(
reqName
);
console
.
log
(
reqPassword
);
console
.
log
(
reqEmail
);
try
{
try
{
const
existingParticipant
=
await
Participant
.
findOne
({
const
existingParticipant
=
await
findParticipantByMeetingIdAndName
(
where
:
{
meetingId
,
MeetingId
:
meetingId
,
reqName
,
name
:
reqName
,
);
},
});
if
(
existingParticipant
)
{
if
(
existingParticipant
)
{
throw
new
Error
()
;
throw
createParticipantIsAlreadyExist
Error
;
}
}
let
passwordEncrypted
=
null
;
let
passwordEncrypted
=
null
;
...
@@ -43,14 +57,28 @@ exports.createParticipant = async (req, res, next) => {
...
@@ -43,14 +57,28 @@ exports.createParticipant = async (req, res, next) => {
passwordEncrypted
=
await
encryptPassword
(
reqPassword
,
next
);
passwordEncrypted
=
await
encryptPassword
(
reqPassword
,
next
);
}
}
const
participantCreated
=
await
Participant
.
create
({
const
participantCreated
=
await
create
Participant
(
name
:
reqName
,
reqName
,
password
:
passwordEncrypted
,
passwordEncrypted
,
email
:
reqEmail
,
reqEmail
,
MeetingId
:
meetingId
,
meetingId
,
}
);
);
return
res
.
status
(
201
).
json
(
ParticipantResponse
.
from
(
participantCreated
));
return
res
.
status
(
201
).
json
(
ParticipantResponse
.
from
(
participantCreated
));
}
catch
(
error
)
{
}
catch
(
error
)
{
return
next
(
error
);
return
next
(
error
);
}
}
};
};
exports
.
getParticipantExistence
=
async
(
req
,
res
,
next
)
=>
{
try
{
const
participant
=
await
findParticipantByMeetingIdAndName
(
req
.
params
.
meetingId
,
req
.
query
.
name
,
);
return
res
.
json
({
exist
:
!!
participant
,
});
}
catch
(
error
)
{
return
next
(
error
);
}
};
This diff is collapsed.
Click to expand it.
errors/participantErrors.js
0 → 100644
+
7
−
0
View file @
a1666477
exports
.
createParticipantIsAlreadyExistError
=
()
=>
{
const
error
=
new
Error
(
'
이미 존재하는 참가자입니다. 같은 이름의 참가자를 중복 생성할 수 없습니다.
'
,
);
error
.
status
=
409
;
return
error
;
};
This diff is collapsed.
Click to expand it.
routes/participant.js
+
6
−
1
View file @
a1666477
const
express
=
require
(
'
express
'
);
const
express
=
require
(
'
express
'
);
const
{
createParticipant
}
=
require
(
'
../controllers/participant
'
);
const
{
createParticipant
,
getParticipantExistence
,
}
=
require
(
'
../controllers/participant
'
);
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
post
(
'
/:meetingId/participants
'
,
createParticipant
);
router
.
post
(
'
/:meetingId/participants
'
,
createParticipant
);
router
.
get
(
'
/:meetingId/participants/existence
'
,
getParticipantExistence
);
module
.
exports
=
router
;
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment