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
9db1e988
Commit
9db1e988
authored
2 weeks ago
by
65160394
Browse files
Options
Downloads
Patches
Plain Diff
Project Round 11
parent
d6e57d85
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
controllers/tourController.js
+16
-4
16 additions, 4 deletions
controllers/tourController.js
models/tourModel.js
+9
-1
9 additions, 1 deletion
models/tourModel.js
views/createtour.ejs
+5
-5
5 additions, 5 deletions
views/createtour.ejs
with
30 additions
and
10 deletions
controllers/tourController.js
+
16
−
4
View file @
9db1e988
const
{
User
,
Tour
}
=
require
(
'
../models/tourModel
'
);
const
{
User
,
Tour
,
company
}
=
require
(
'
../models/tourModel
'
);
const
pool
=
require
(
'
../config/database
'
);
exports
.
getTours
=
async
(
req
,
res
)
=>
{
...
...
@@ -147,8 +147,18 @@ exports.updateProfile = async (req, res) => {
//CRUD
// แสดงฟอร์มสร้างทัวร์
exports
.
getCreateTour
=
(
req
,
res
)
=>
{
res
.
render
(
'
createtour
'
);
// ฟังก์ชันแสดงฟอร์มสร้างทัวร์
exports
.
getCreateTour
=
async
(
req
,
res
)
=>
{
try
{
// ดึงข้อมูลบริษัททั้งหมดจากฐานข้อมูล
const
companies
=
await
company
.
getAllCompanies
();
// ส่งข้อมูลบริษัทไปยัง view 'createtour.ejs'
res
.
render
(
'
createtour
'
,
{
companies
});
}
catch
(
error
)
{
console
.
error
(
'
Error fetching companies:
'
,
error
);
res
.
status
(
500
).
send
(
'
เกิดข้อผิดพลาดในการดึงข้อมูลบริษัท
'
);
}
};
// บันทึกทัวร์ใหม่
...
...
@@ -198,6 +208,8 @@ exports.postCreateTour = async (req, res) => {
res
.
render
(
'
createtour
'
,
{
message
:
'
เกิดข้อผิดพลาดในการสร้างทัวร์
'
});
}
};
//edit
exports
.
getEditTour
=
async
(
req
,
res
)
=>
{
try
{
const
tour
=
await
Tour
.
getTourById
(
req
.
params
.
id
);
...
...
@@ -247,7 +259,7 @@ exports.postEditTour = async (req, res) => {
}
};
//delete
exports
.
deleteTour
=
async
(
req
,
res
)
=>
{
try
{
const
tourId
=
req
.
params
.
id
;
...
...
This diff is collapsed.
Click to expand it.
models/tourModel.js
+
9
−
1
View file @
9db1e988
...
...
@@ -137,4 +137,12 @@ class User {
}
}
module
.
exports
=
{
User
,
Tour
};
class
company
{
static
async
getAllCompany
()
{
const
query
=
'
SELECT * FROM company
'
;
const
[
rows
]
=
await
pool
.
execute
(
query
);
return
rows
;
}
}
module
.
exports
=
{
User
,
Tour
,
company
};
This diff is collapsed.
Click to expand it.
views/createtour.ejs
+
5
−
5
View file @
9db1e988
...
...
@@ -30,12 +30,12 @@
<div>
<label
for=
"tourCompany"
>
บริษัท:
</label>
<select
id=
"tourCompany"
name=
"company_id"
required
>
<option
value=
""
re
>
เลือกบริษัท
</option>
<option
value=
"1"
>
Amazing Travel
</option>
<option
value=
"
2"
>
Wonderful Tours
</option>
<option
value=
"3"
>
Explore Asia
</option
>
<option
value=
""
>
เลือกบริษัท
</option>
<
%
companies.forEach(company =
>
{
%
>
<option
value=
"
<%= company.id %>"
><
%=
company.name
%
>
</option>
<
%
})
%
>
</select>
</div>
</div>
<button
type=
"submit"
>
สร้างโปรแกรม Tour
</button>
</form>
</main>
...
...
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