This commit is contained in:
Iliyan Angelov
2025-11-16 15:12:43 +02:00
parent 824eec6190
commit 93d4c1df80
54 changed files with 1606 additions and 1612 deletions

View File

@@ -1,31 +1,31 @@
# 🚀 QUICK START - Server Setup
## Bước 1: Copy file .env
## Step 1: Copy .env file
```bash
cd d:/hotel-booking/server
cp .env.example .env
```
> File .env đã được tạo sẵn với cấu hình mặc định
> The .env file has been pre-created with default configuration
## Bước 2: Tạo Database (nếu chưa có)
## Step 2: Create Database (if not exists)
```bash
# Mở MySQL command line
# Open MySQL command line
mysql -u root -p
# Tạo database
# Create database
CREATE DATABASE hotel_db;
# Thoát
# Exit
exit;
```
## Bước 3: Chạy Migrations
## Step 3: Run Migrations
```bash
cd d:/hotel-booking/server
npm run migrate
```
Lệnh này sẽ tạo các bảng:
This command will create the following tables:
- roles
- users
- refresh_tokens
@@ -41,23 +41,23 @@ Lệnh này sẽ tạo các bảng:
- password_reset_tokens
- reviews
## Bước 4: (Optional) Seed Data
## Step 4: (Optional) Seed Data
```bash
npm run seed
```
Lệnh này sẽ tạo:
This command will create:
- 3 roles: admin, staff, customer
- Demo users
- Demo rooms & room types
- Demo bookings
## Bước 5: Start Server
## Step 5: Start Server
```bash
npm run dev
```
Bạn sẽ thấy:
You will see:
```
✅ Database connection established successfully
📊 Database models synced
@@ -67,12 +67,12 @@ Bạn sẽ thấy:
🏥 Health: http://localhost:3000/health
```
## Bước 6: Test API
## Step 6: Test API
### Health Check
Mở browser: http://localhost:3000/health
Open browser: http://localhost:3000/health
### Test Login (sau khi seed data)
### Test Login (after seeding data)
```bash
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
@@ -81,34 +81,34 @@ curl -X POST http://localhost:3000/api/auth/login \
## ⚠️ Troubleshooting
### Lỗi: "Access denied for user 'root'"
**Giải pháp:** Sửa DB_PASS trong file `.env`
### Error: "Access denied for user 'root'"
**Solution:** Update DB_PASS in `.env` file
```bash
DB_PASS=your_mysql_password
```
### Lỗi: "Unknown database 'hotel_db'"
**Giải pháp:** Tạo database thủ công (Bước 2)
### Error: "Unknown database 'hotel_db'"
**Solution:** Create database manually (Step 2)
### Lỗi: "Port 3000 already in use"
**Giải pháp:** Đổi PORT trong `.env`
### Error: "Port 3000 already in use"
**Solution:** Change PORT in `.env`
```bash
PORT=3001
```
### Lỗi: "Cannot find module"
**Giải pháp:** Cài lại dependencies
### Error: "Cannot find module"
**Solution:** Reinstall dependencies
```bash
npm install
```
## 📝 Next Steps
1. ✅ Server đang chạy
2. ✅ Database đã setup
3. ✅ API endpoints sẵn sàng
4. 🔜 Test với frontend login form
5. 🔜 Implement các API còn lại
1. ✅ Server is running
2. ✅ Database is set up
3. ✅ API endpoints are ready
4. 🔜 Test with frontend login form
5. 🔜 Implement remaining APIs
## 🧪 Test với Postman
@@ -146,14 +146,14 @@ Authorization: Bearer YOUR_ACCESS_TOKEN
## ✅ Checklist
- [ ] MySQL đang chạy
- [ ] File .env đã tạo và cấu hình đúng
- [ ] Database hotel_db đã tạo
- [ ] Migrations đã chạy thành công
- [ ] Server đang chạy (port 3000)
- [ ] Health check trả về 200 OK
- [ ] Frontend .env đã có VITE_API_URL=http://localhost:3000
- [ ] Frontend đang chạy (port 5173)
- [ ] MySQL is running
- [ ] .env file has been created and configured correctly
- [ ] Database hotel_db has been created
- [ ] Migrations have run successfully
- [ ] Server is running (port 3000)
- [ ] Health check returns 200 OK
- [ ] Frontend .env has VITE_API_URL=http://localhost:3000
- [ ] Frontend is running (port 5173)
## 🎯 Ready to Test Login!
@@ -162,4 +162,4 @@ Authorization: Bearer YOUR_ACCESS_TOKEN
3. Login page: http://localhost:5173/login ✅
4. API endpoint: http://localhost:3000/api/auth/login ✅
**Tất cả sẵn sàng!** Giờ có thể test login form từ frontend! 🚀
**Everything is ready!** You can now test the login form from the frontend! 🚀

View File

@@ -222,7 +222,7 @@ const resetPassword = async (req, res, next) => {
}
if (
error.message.includes('must be different') ||
error.message.includes('Mật khẩu mới')
error.message.includes('New password')
) {
return res.status(400).json({
status: 'error',

View File

@@ -19,7 +19,7 @@ const addFavorite = async (req, res, next) => {
if (!room) {
return res.status(404).json({
status: 'error',
message: 'Không tìm thấy phòng',
message: 'Room not found',
});
}
@@ -34,7 +34,7 @@ const addFavorite = async (req, res, next) => {
if (existingFavorite) {
return res.status(400).json({
status: 'error',
message: 'Phòng đã có trong danh sách yêu thích',
message: 'Room already in favorites list',
});
}
@@ -46,7 +46,7 @@ const addFavorite = async (req, res, next) => {
res.status(201).json({
status: 'success',
message: 'Đã thêm vào danh sách yêu thích',
message: 'Added to favorites list',
data: {
favorite,
},
@@ -75,7 +75,7 @@ const removeFavorite = async (req, res, next) => {
if (!favorite) {
return res.status(404).json({
status: 'error',
message: 'Không tìm thấy phòng trong danh sách yêu thích',
message: 'Room not found in favorites list',
});
}
@@ -83,7 +83,7 @@ const removeFavorite = async (req, res, next) => {
res.status(200).json({
status: 'success',
message: 'Đã xóa khỏi danh sách yêu thích',
message: 'Removed from favorites list',
});
} catch (error) {
next(error);

View File

@@ -9,7 +9,7 @@ module.exports = {
// booking_number, service_name, rest of fields
{
booking_number: 'BK2025010001',
service_name: 'Dịch vụ phòng - Bữa sáng',
service_name: 'Room Service - Breakfast',
quantity: 2,
unit_price: 150000,
total_price: 300000,
@@ -20,7 +20,7 @@ module.exports = {
},
{
booking_number: 'BK2025010001',
service_name: 'Dịch vụ giặt ủi - Thông thường',
service_name: 'Laundry Service - Regular',
quantity: 3,
unit_price: 60000,
total_price: 180000,
@@ -31,7 +31,7 @@ module.exports = {
},
{
booking_number: 'BK2025010002',
service_name: 'Dịch vụ phòng - Bữa sáng',
service_name: 'Room Service - Breakfast',
quantity: 1,
unit_price: 150000,
total_price: 150000,
@@ -42,7 +42,7 @@ module.exports = {
},
{
booking_number: 'BK2025010002',
service_name: 'Spa - Massage truyền thống',
service_name: 'Spa - Traditional Massage',
quantity: 1,
unit_price: 500000,
total_price: 500000,
@@ -53,7 +53,7 @@ module.exports = {
},
{
booking_number: 'BK2025010002',
service_name: 'Trả phòng muộn',
service_name: 'Late Check-out',
quantity: 1,
unit_price: 500000,
total_price: 500000,
@@ -64,7 +64,7 @@ module.exports = {
},
{
booking_number: 'BK2025010003',
service_name: 'Đón sân bay',
service_name: 'Airport Pickup',
quantity: 1,
unit_price: 400000,
total_price: 400000,
@@ -75,7 +75,7 @@ module.exports = {
},
{
booking_number: 'BK2025010005',
service_name: 'Đón sân bay',
service_name: 'Airport Pickup',
quantity: 1,
unit_price: 400000,
total_price: 400000,
@@ -86,7 +86,7 @@ module.exports = {
},
{
booking_number: 'BK2025010005',
service_name: 'Spa - Liệu pháp hương thơm',
service_name: 'Spa - Aromatherapy',
quantity: 1,
unit_price: 700000,
total_price: 700000,