Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Project
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
65160394
Project
Commits
d6e57d85
Commit
d6e57d85
authored
2 weeks ago
by
65160394
Browse files
Options
Downloads
Patches
Plain Diff
Project Round 11
parent
c3b517dc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controllers/tourController.js
+12
-2
12 additions, 2 deletions
controllers/tourController.js
models/tourModel.js
+5
-33
5 additions, 33 deletions
models/tourModel.js
with
17 additions
and
35 deletions
controllers/tourController.js
+
12
−
2
View file @
d6e57d85
...
...
@@ -253,13 +253,23 @@ exports.deleteTour = async (req, res) => {
const
tourId
=
req
.
params
.
id
;
console
.
log
(
"
Request to delete tour ID:
"
,
tourId
);
// ตรวจสอบค่า ID
// ตรวจสอบว่ามีการส่ง tourId มาหรือไม่
if
(
!
tourId
)
{
return
res
.
status
(
400
).
send
(
"
Tour ID is required
"
);
}
await
Tour
.
deleteTour
(
tourId
);
res
.
redirect
(
'
/
'
);
// ลบทัวร์
const
tour
=
await
Tour
.
deleteTourById
(
tourId
);
// ตรวจสอบผลลัพธ์หลังจากการลบ
if
(
tour
.
affectedRows
===
0
)
{
return
res
.
status
(
404
).
send
(
"
Tour not found
"
);
}
// Redirect ไปที่หน้าแรกหรือหน้าอื่น
res
.
redirect
(
'
/
'
);
}
catch
(
error
)
{
console
.
error
(
"
Error deleting tour:
"
,
error
);
res
.
status
(
500
).
send
(
error
.
message
);
}
};
...
...
This diff is collapsed.
Click to expand it.
models/tourModel.js
+
5
−
33
View file @
d6e57d85
...
...
@@ -93,39 +93,11 @@ class Tour {
}
// ลบทัวร์
static
async
deleteTour
(
id
)
{
try
{
console
.
log
(
"
Deleting tour with ID:
"
,
id
);
// เช็คค่า ID ที่รับมา
if
(
!
id
)
{
throw
new
Error
(
"
Tour ID is required
"
);
}
// ตรวจสอบว่าทัวร์มีอยู่จริง
const
checkQuery
=
'
SELECT * FROM tours WHERE id = ?
'
;
const
[
tours
]
=
await
pool
.
execute
(
checkQuery
,
[
id
]);
if
(
tours
.
length
===
0
)
{
throw
new
Error
(
"
Tour not found
"
);
}
// แจ้งเตือนก่อนลบ
const
userConfirmation
=
confirm
(
`คุณต้องการลบทัวร์ "
${
tours
[
0
].
name
}
" หรือไม่?`
);
if
(
!
userConfirmation
)
{
throw
new
Error
(
"
ลบทัวร์ถูกยกเลิก
"
);
}
// ลบข้อมูลทัวร์จากฐานข้อมูล
const
deleteQuery
=
'
DELETE FROM tours WHERE id = ?
'
;
const
[
result
]
=
await
pool
.
execute
(
deleteQuery
,
[
id
]);
console
.
log
(
"
Delete result:
"
,
result
);
return
result
;
}
catch
(
error
)
{
console
.
error
(
'
Error deleting tour:
'
,
error
);
throw
new
Error
(
'
เกิดข้อผิดพลาดในการลบทัวร์
'
);
}
// ลบทัวร์จากฐานข้อมูล
static
async
deleteTourById
(
id
)
{
const
query
=
'
DELETE FROM tours WHERE id = ?
'
;
const
[
result
]
=
await
pool
.
execute
(
query
,
[
id
]);
return
result
;
}
...
...
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