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
07d56c31
Commit
07d56c31
authored
6 months ago
by
Jinyeong Kim
Browse files
Options
Downloads
Patches
Plain Diff
fix add plan
parent
48f9c3ae
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
controllers/TripController.js
+27
-7
27 additions, 7 deletions
controllers/TripController.js
with
27 additions
and
7 deletions
controllers/TripController.js
+
27
−
7
View file @
07d56c31
...
...
@@ -105,25 +105,45 @@ const addCollaborator = async (req, res) => {
// 하루 계획 추가
const
addDayPlan
=
async
(
req
,
res
)
=>
{
try
{
const
{
dayKey
,
places
,
route
}
=
req
.
body
;
const
trip
=
await
Trip
.
findById
(
req
.
params
.
id
);
const
{
dayKey
,
places
,
route
}
=
req
.
body
;
// 요청 데이터
const
trip
=
await
Trip
.
findById
(
req
.
params
.
id
);
// Trip 찾기
if
(
!
trip
)
{
return
res
.
status
(
404
).
json
({
message
:
'
Trip not found
'
});
}
if
(
!
trip
.
plans
)
{
trip
.
plans
=
new
Map
();
// `plans` 디버깅
console
.
log
(
'
Existing Plans:
'
,
JSON
.
stringify
(
trip
.
plans
,
null
,
2
));
// `Map`을 사용하여 dayKey 접근
const
currentDay
=
trip
.
plans
.
get
(
dayKey
);
if
(
!
currentDay
)
{
return
res
.
status
(
404
).
json
({
message
:
`Day
${
dayKey
}
not found in trip plans`
});
}
trip
.
plans
.
set
(
dayKey
,
{
places
,
route
});
// 데이터 업데이트
if
(
places
)
currentDay
.
places
=
places
;
if
(
route
)
currentDay
.
route
=
route
;
// `Map`에 업데이트된 day 데이터 설정
trip
.
plans
.
set
(
dayKey
,
currentDay
);
// Mongoose에 변경 사항 알림
trip
.
markModified
(
'
plans
'
);
console
.
log
(
'
Before Save:
'
,
JSON
.
stringify
(
trip
.
plans
.
get
(
dayKey
),
null
,
2
));
// 변경 사항 저장
const
updatedTrip
=
await
trip
.
save
();
res
.
status
(
200
).
json
(
updatedTrip
);
console
.
log
(
'
After Save:
'
,
JSON
.
stringify
(
updatedTrip
.
plans
.
get
(
dayKey
),
null
,
2
));
res
.
status
(
200
).
json
(
updatedTrip
.
plans
.
get
(
dayKey
));
// 수정된 day 데이터 반환
}
catch
(
err
)
{
console
.
error
(
'
Error:
'
,
err
);
console
.
error
(
'
Error
updating day
:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
err
.
message
});
}
};
module
.
exports
=
{
...
...
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