Skip to content

Commit

Permalink
delete cache when create, update tour
Browse files Browse the repository at this point in the history
  • Loading branch information
augustus281 committed May 23, 2024
1 parent e6af0e1 commit 3993fe8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions server/src/controllers/tour.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ class TourController {
list_image: JSON.stringify(list_image),
status: StatusTour.WAITING
});

// Delete cached data from Redis
redisClient.del("waiting_tours")

// Associate destinations with the tour
for (const dest of destinations) {
Expand All @@ -129,6 +126,11 @@ class TourController {
defaults: { attraction_id: exist_attraction.attraction_id, tour_id: newTour.tour_id }
})
}

// Delete cached data from Redis
redisClient.del("online_tours")
redisClient.del("waiting_tours")
redisClient.del("tours")

return res.status(201).json({
message: 'Create tour successfully!',
Expand All @@ -147,6 +149,8 @@ class TourController {
if (!newTour) return res.status(400).json({ message: "Failed to copy tour!" })

redisClient.delete("waiting_tours")
redisClient.delete("tours")

return res.status(201).json({
message: "Copy tour successfully!",
data: newTour
Expand Down Expand Up @@ -177,6 +181,7 @@ class TourController {
// Deleted cached data from Redis
redisClient.del("online_tours")
redisClient.del("waiting_tours")
redisClient.del("tours")

return res.status(200).json({
message: "Update tour successfully!",
Expand All @@ -197,6 +202,11 @@ class TourController {
const link_image = await cloudinary.uploader.upload(cover_image)
tour.cover_image = link_image.secure_url
await tour.save()

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

return res.status(200).json({
message: "Upload cover image successfully!",
link_image: link_image.secure_url
Expand Down
4 changes: 3 additions & 1 deletion server/src/controllers/tour_guide.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { isAdmin } = require("../middlewares/authenticate");
const User = require("../models/user.model");
const { Op } = require("sequelize");
const Task = require("../models/task.model");
const Tour = require("../models/tour.model");

const role_user = {
ADMIN: 'admin',
Expand Down Expand Up @@ -196,7 +197,8 @@ class TourGuideController {
const allTasks = await Task.findAll({
where: {
user_id: user_id
}
},
include: [Tour]
})

return res.status(200).json({
Expand Down

0 comments on commit 3993fe8

Please sign in to comment.