Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
festivelo_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
Festivelo
festivelo_backend
Commits
d9b3938e
Commit
d9b3938e
authored
6 months ago
by
pjookim
Browse files
Options
Downloads
Patches
Plain Diff
Refactor collaborator management in TripController
parent
287d7a3c
No related branches found
No related tags found
1 merge request
!15
Hi
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
controllers/TripController.js
+23
-14
23 additions, 14 deletions
controllers/TripController.js
models/trips.js
+2
-1
2 additions, 1 deletion
models/trips.js
with
25 additions
and
15 deletions
controllers/TripController.js
+
23
−
14
View file @
d9b3938e
...
...
@@ -66,29 +66,38 @@ const addCollaborator = async (req, res) => {
try
{
const
{
collaboratorEmail
}
=
req
.
body
;
// Verify if the collaboratorEmail corresponds to a valid user
const
user
=
await
User
.
findOne
({
email
:
collaboratorEmail
});
if
(
!
user
)
{
return
res
.
status
(
404
).
json
({
message
:
'
User not found
'
});
const
collaborator
=
await
User
.
findOne
({
email
:
collaboratorEmail
});
if
(
!
collaborator
)
{
return
res
.
status
(
404
).
json
({
message
:
'
해당 이메일의 사용자를 찾을 수 없습니다.
'
});
}
const
trip
=
await
Trip
.
findById
(
req
.
params
.
id
).
populate
(
'
creaate_by
'
);
if
(
!
trip
)
return
res
.
status
(
404
).
json
({
message
:
'
Trip not found
'
});
const
trip
=
await
Trip
.
findById
(
req
.
params
.
id
).
populate
(
'
create_by
'
);
if
(
!
trip
)
{
return
res
.
status
(
404
).
json
({
message
:
'
여행을 찾을 수 없습니다.
'
});
}
const
isAlreadyCollaborator
=
trip
.
collaborators
.
some
(
collab
=>
collab
.
toString
()
===
collaborator
.
_id
.
toString
()
);
// Check if the user is already a collaborator
if
(
trip
.
collaborators
.
some
(
collaborator
=>
collaborator
.
email
===
collaboratorEmail
))
{
return
res
.
status
(
400
).
json
({
message
:
'
User is already a collaborator
'
});
if
(
isAlreadyCollaborator
)
{
return
res
.
status
(
400
).
json
({
message
:
'
이미 공동작업자로 등록된 사용자입니다.
'
});
}
// Check if the email is the creator's email
if
(
trip
.
create_by
.
email
===
collaboratorEmail
)
{
return
res
.
status
(
400
).
json
({
message
:
'
Creator cannot be added as a collaborator
'
});
if
(
trip
.
create_by
.
_id
.
toString
()
===
collaborator
.
_id
.
toString
())
{
return
res
.
status
(
400
).
json
({
message
:
'
생성자는 공동작업자로 추가할 수 없습니다.
'
});
}
trip
.
collaborators
.
push
(
{
email
:
collaborator
Email
}
);
trip
.
collaborators
.
push
(
collaborator
.
_id
);
await
trip
.
save
();
res
.
status
(
200
).
json
(
trip
);
const
updatedTrip
=
await
Trip
.
findById
(
trip
.
_id
)
.
populate
(
'
create_by
'
)
.
populate
(
'
collaborators
'
);
res
.
status
(
200
).
json
(
updatedTrip
);
}
catch
(
err
)
{
console
.
error
(
'
공동작업자 추가 오류:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
err
.
message
});
}
};
...
...
This diff is collapsed.
Click to expand it.
models/trips.js
+
2
−
1
View file @
d9b3938e
...
...
@@ -27,7 +27,8 @@ const tripSchema = new mongoose.Schema({
location
:
{
type
:
String
,
required
:
true
},
create_by
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'
User
'
,
required
:
true
},
collaborators
:
[{
email
:
{
type
:
String
,
required
:
true
}
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'
User
'
}],
plans
:
{
type
:
Map
,
// Object 대신 Map 사용
...
...
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