Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
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
websystem
WebBack
Commits
387f65ca
Commit
387f65ca
authored
4 months ago
by
조대희
Browse files
Options
Downloads
Patches
Plain Diff
refactor: 스케줄 생성/수정/삭제 시 transaction 적용 (
#5
)
parent
57bc299c
No related branches found
Branches containing commit
No related tags found
2 merge requests
!31
Develop
,
!6
[#5] Schedule 서비스 로직 개발
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/scheduleService.js
+16
-3
16 additions, 3 deletions
services/scheduleService.js
with
16 additions
and
3 deletions
services/scheduleService.js
+
16
−
3
View file @
387f65ca
...
...
@@ -19,6 +19,8 @@ class schedulService {
* 사용자 스케줄 생성
*/
async
createSchedule
({
userId
,
title
,
start_time
,
end_time
,
is_fixed
})
{
const
transaction
=
await
Schedule
.
sequelize
.
transaction
();
try
{
// 일정 시작 시간 - 종료 시간 유효성 검사
...
...
@@ -41,9 +43,11 @@ class schedulService {
expiry_date
:
is_fixed
?
null
:
this
.
getNextMonday
()
};
const
schedule
=
await
Schedule
.
create
(
scheduleData
);
const
schedule
=
await
Schedule
.
create
(
scheduleData
,
{
transaction
});
await
transaction
.
commit
();
return
schedule
;
}
catch
(
error
)
{
await
transaction
.
rollback
();
throw
new
Error
(
`Failed to create schedule:
${
error
.
message
}
`
);
}
}
...
...
@@ -52,6 +56,8 @@ class schedulService {
* 사용자 스케줄 수정
*/
async
updateSchedule
(
id
,
userId
,
updateData
)
{
const
transaction
=
await
Schedule
.
sequelize
.
transaction
();
try
{
const
schedule
=
await
Schedule
.
findOne
({
where
:
{
id
,
user_id
:
userId
}
...
...
@@ -75,9 +81,11 @@ class schedulService {
// 스케줄 타입 변경하지 못하도록 update값 삭제 -> 기존값 유지
delete
updateData
.
is_fixed
;
await
schedule
.
update
(
updateData
);
await
schedule
.
update
(
updateData
,
{
transaction
});
await
transaction
.
commit
();
return
schedule
;
}
catch
(
error
)
{
await
transaction
.
rollback
();
throw
new
Error
(
`Failed to update schedule:
${
error
.
message
}
`
);
}
}
...
...
@@ -86,17 +94,22 @@ class schedulService {
* 사용자 스케줄 삭제
*/
async
deleteSchedule
(
id
,
userId
)
{
const
transaction
=
await
Schedule
.
sequelize
.
transaction
();
try
{
const
schedule
=
await
Schedule
.
destroy
({
where
:
{
id
,
user_id
:
userId
}
where
:
{
id
,
user_id
:
userId
},
transaction
});
if
(
!
schedule
)
{
throw
new
Error
(
'
Schedule not found
'
);
}
await
transaction
.
commit
();
return
true
;
}
catch
(
error
)
{
await
transaction
.
rollback
();
throw
new
Error
(
`Failed to delete schedule:
${
error
.
message
}
`
);
}
}
...
...
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