Add express routes

This commit is contained in:
Alex Piqueras 2024-12-02 11:17:14 +01:00
parent ffd23217da
commit 4d1da02b5f
4 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import { Router } from "express";
import BookingController from "../controllers/booking.controller";
class BookingRoutes {
router = Router();
controller = new BookingController();
constructor() {
this.intializeRoutes();
}
intializeRoutes() {
// Create a new Booking
this.router.post("/", this.controller.create);
// Retrieve all Bookings
this.router.get("/", this.controller.findAll);
// Retrieve a single Booking with id
this.router.get("/:id", this.controller.findOne);
// Update a Booking with id
this.router.put("/:id", this.controller.update);
// Delete a Booking with id
this.router.delete("/:id", this.controller.delete);
}
}
export default new BookingRoutes().router;

View File

@ -0,0 +1,31 @@
import { Router } from "express";
import ClientController from "../controllers/client.controller";
class ClientRoutes {
router = Router();
controller = new ClientController();
constructor() {
this.intializeRoutes();
}
intializeRoutes() {
// Create a new Client
this.router.post("/", this.controller.create);
// Retrieve all Clients
this.router.get("/", this.controller.findAll);
// Retrieve a single Client with id
this.router.get("/:id", this.controller.findOne);
// Update a Client with id
this.router.put("/:id", this.controller.update);
// Delete a Client with id
this.router.delete("/:id", this.controller.delete);
}
}
export default new ClientRoutes().router;

View File

@ -0,0 +1,31 @@
import { Router } from "express";
import HotelController from "../controllers/hotel.controller";
class HotelRoutes {
router = Router();
controller = new HotelController();
constructor() {
this.intializeRoutes();
}
intializeRoutes() {
// Create a new Hotel
this.router.post("/", this.controller.create);
// Retrieve all Hotels
this.router.get("/", this.controller.findAll);
// Retrieve a single Hotel with id
this.router.get("/:id", this.controller.findOne);
// Update a Hotel with id
this.router.put("/:id", this.controller.update);
// Delete a Hotel with id
this.router.delete("/:id", this.controller.delete);
}
}
export default new HotelRoutes().router;

13
src/routes/index.ts Normal file
View File

@ -0,0 +1,13 @@
import { Application } from "express";
import hotelRoutes from "./hotel.routes";
import clientRoutes from "./client.routes";
import bookingRoutes from "./booking.routes";
export default class Routes {
constructor(app: Application) {
app.use("/api/hotels", hotelRoutes);
app.use("/api/client", clientRoutes);
app.use("/api/booking", bookingRoutes);
}
}