From ed1145e6a325d7d766c1ae43c129e164aff8bb38 Mon Sep 17 00:00:00 2001 From: DucHuy2801 Date: Sun, 19 May 2024 03:11:18 +0700 Subject: [PATCH] tour guide controller --- .../src/controllers/tour_guide.controller.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 server/src/controllers/tour_guide.controller.js diff --git a/server/src/controllers/tour_guide.controller.js b/server/src/controllers/tour_guide.controller.js new file mode 100644 index 0000000..f2be0ca --- /dev/null +++ b/server/src/controllers/tour_guide.controller.js @@ -0,0 +1,50 @@ +'use strict' + +const GuideTour = require("../models/guide_tour.model"); +const { findTourById } = require("../services/tour.service") + +class TourGuideController { + assignTourToTourGuide = async (req, res, next) => { + try { + const { tour_id, tour_guide_id } = req.body + const tour = await findTourById(tour_id); + if (!tour) { + return res.status(404).json({ message: "Not found to assign!" }) + } + await GuideTour.create({ + tour_id, tour_guide_id + }) + return res.status(200).json({ + message: "Assign tour for tour guide successfully!" + }) + } catch (error) { + return res.status(500).json({ message: error.message }) + } + } + + responseTask = async (req, res, next) => { + try { + const { tour_id, reason, tour_guide_id } = req.body + const guideTour = await GuideTour.findOne({ + where: { + tour_id, + tour_guide_id + } + }) + + if (!guideTour) { + return res.status(404).json({ message: "Not found tour is assigned!" }) + } + + // TODO + + return res.status(200).json({ message: "Response task successfully!" }) + } catch (error) { + return res.status(500).json({ + message: error.message + }) + } + } +} + +module.exports = new TourGuideController() \ No newline at end of file