Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add convertWaitingToOnlineTour #21

Merged
merged 3 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions server/src/controllers/tour.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,27 @@ class TourController {
}
}

convertWaitingToOnlineTour = async(req, res, next) => {
try {
const tour_id = req.params.tour_id
const tour = await Tour.findOne({ where : { tour_id, status: StatusTour.WAITING }})
if (!tour) return res.status(404).json({ Message: "Not found tour!"})
tour.status = StatusTour.ONLINE
await tour.save()

redisClient.del("waiting_tours")
redisClient.del("online_tours")
redisClient.del("deleted_tours")

return res.status(200).json({
message: "Convert tour successfully",
tour: tour
})
} catch (error) {
return res.status(500).json({ message: error.message })
}
}

deleteTour = async (req, res, next) => {
try {
const tour_id = req.params.tour_id
Expand Down
234 changes: 134 additions & 100 deletions server/src/postman/BKTravel.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,106 @@
{
"name": "User",
"item": [
{
"name": "Get Wishlist by user",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNjA3NDI0NiwiZXhwIjoxNzA2MDc2MDQ2fQ.e8ceK8R1EA9l2Rg0L5EP9foKw1mja0OJuIFNqj8TiRM"
}
],
"url": {
"raw": "http://localhost:8080/api/v1/users/2/wishlist",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"users",
"2",
"wishlist"
]
}
},
"response": []
},
{
"name": "Add tour to wishlist",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eTI4MDExQGdtYWlsLmNvbSIsInJvbGVfdXNlciI6ImN1c3RvbWVyIiwiaWF0IjoxNzE1NjA4Mjk2LCJleHAiOjE3MTU2MTAwOTZ9.yWxUVFMZqMSUQuqiKKFqXXzQePmi79wyG0zfhxCHRZ4"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"user_id\": 2,\r\n \"tour_id\": 1\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/api/v1/users/wishlist",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"users",
"wishlist"
]
}
},
"response": []
},
{
"name": "Add tour to cart",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"user_id\": \"1\",\r\n \"tour\": {\r\n \"tour_id\": 2,\r\n \"adult_quantity\": 1,\r\n \"child_quantity\": 2\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/api/v1/users/carts",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"users",
"carts"
]
}
},
"response": []
},
{
"name": "Register",
"request": {
Expand Down Expand Up @@ -480,106 +580,6 @@
}
},
"response": []
},
{
"name": "Get Wishlist by user",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNjA3NDI0NiwiZXhwIjoxNzA2MDc2MDQ2fQ.e8ceK8R1EA9l2Rg0L5EP9foKw1mja0OJuIFNqj8TiRM"
}
],
"url": {
"raw": "http://localhost:8080/api/v1/users/2/wishlist",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"users",
"2",
"wishlist"
]
}
},
"response": []
},
{
"name": "Add tour to wishlist",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eTI4MDExQGdtYWlsLmNvbSIsInJvbGVfdXNlciI6ImN1c3RvbWVyIiwiaWF0IjoxNzE1NjA4Mjk2LCJleHAiOjE3MTU2MTAwOTZ9.yWxUVFMZqMSUQuqiKKFqXXzQePmi79wyG0zfhxCHRZ4"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"user_id\": 2,\r\n \"tour_id\": 1\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/api/v1/users/wishlist",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"users",
"wishlist"
]
}
},
"response": []
},
{
"name": "Add tour to cart",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"user_id\": \"1\",\r\n \"tour\": {\r\n \"tour_id\": 2,\r\n \"adult_quantity\": 1,\r\n \"child_quantity\": 2\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/api/v1/users/carts",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"users",
"carts"
]
}
},
"response": []
}
]
},
Expand Down Expand Up @@ -1175,6 +1175,40 @@
},
"response": []
},
{
"name": "Convert waiting to online",
"request": {
"method": "PATCH",
"header": [
{
"key": "Authorization",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6Imh1eS5uZ3V5ZW4yODAxMjAwMkBoY211dC5lZHUudm4iLCJyb2xlX3VzZXIiOiJjdXN0b21lciIsImlhdCI6MTcwNTg1OTEwMSwiZXhwIjoxNzA1ODYwOTAxfQ.CVQhYHm4g_-xFLV-rIezkRoyzOPogEkxm5nzrX6S930"
}
],
"url": {
"raw": "http://localhost:8080/api/v1/tours/:tour_id/public",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"api",
"v1",
"tours",
":tour_id",
"public"
],
"variable": [
{
"key": "tour_id",
"value": "13"
}
]
}
},
"response": []
},
{
"name": "Search Tour",
"protocolProfileBehavior": {
Expand Down
1 change: 1 addition & 0 deletions server/src/routes/tour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ router.get("/:tour_id/schedules", asyncHandler(tourController.getScheduleByIdTou
router.put("/:tour_id", formidableMiddleware(), authenticate, asyncHandler(tourController.updateTour))
router.put("/:tour_id/response", authenticate, asyncHandler(tourController.responseTour))
router.put("/recover/:tour_id", authenticate, asyncHandler(tourController.recoverTour))
router.patch("/:tour_id/public", authenticate, asyncHandler(tourController.convertWaitingToOnlineTour))
router.post("/:tour_id/upload", authenticate, asyncHandler(tourController.updateCoverImageTour))
router.delete("/:tour_id", authenticate, asyncHandler(tourController.deleteTour))

Expand Down
Loading