114 lines
4.2 KiB
TypeScript
114 lines
4.2 KiB
TypeScript
import type { AbstractFileStorage } from "@/common/services/file-storage/abstract.file-storage";
|
|
import { LocalFileStorage } from "@/common/services/file-storage/local.file-storage";
|
|
import { serverConfig } from "@/configs/server.config";
|
|
import { AirlineController } from "@/modules/airline/airline.controller";
|
|
import { AirlineMapper } from "@/modules/airline/airline.mapper";
|
|
import { AirportController } from "@/modules/airport/airport.controller";
|
|
import { AirportMapper } from "@/modules/airport/airport.mapper";
|
|
import { CityController } from "@/modules/city/city.controller";
|
|
import { CityMapper } from "@/modules/city/city.mapper";
|
|
import { CountryController } from "@/modules/country/country.controller";
|
|
import { CountryMapper } from "@/modules/country/country.mapper";
|
|
import { FlightController } from "@/modules/flight/flight.controller";
|
|
import { FlightMapper } from "@/modules/flight/flight.mapper";
|
|
import { HotelFacilityController } from "@/modules/hotel-facility/hotel-facility.controller";
|
|
import { HotelFacilityMapper } from "@/modules/hotel-facility/hotel-facility.mapper";
|
|
import { HotelController } from "@/modules/hotel/hotel.controller";
|
|
import { HotelMapper } from "@/modules/hotel/hotel.mapper";
|
|
import { PackageController } from "@/modules/package/package.controller";
|
|
import { PackageMapper } from "@/modules/package/package.mapper";
|
|
import { TransportationController } from "@/modules/transportation/transportation.controller";
|
|
import { TransportationMapper } from "@/modules/transportation/transportation.mapper";
|
|
import compression from "compression";
|
|
import cors from "cors";
|
|
import express from "express";
|
|
import helmet from "helmet";
|
|
|
|
export class Application {
|
|
private readonly _app: express.Application;
|
|
|
|
// Services
|
|
private _fileStorage!: AbstractFileStorage;
|
|
|
|
public constructor() {
|
|
this._app = express();
|
|
}
|
|
|
|
public initializeServices() {
|
|
this._fileStorage = new LocalFileStorage();
|
|
}
|
|
|
|
public initializeMiddlewares() {
|
|
this._app.use(helmet());
|
|
this._app.use(cors());
|
|
this._app.use(compression());
|
|
this._app.use(express.json({ limit: "1mb" }));
|
|
this._app.use(express.urlencoded());
|
|
}
|
|
|
|
public initializeRouters() {
|
|
const countryMapper = new CountryMapper();
|
|
const cityMapper = new CityMapper(countryMapper);
|
|
const airlineMapper = new AirlineMapper();
|
|
const airportMapper = new AirportMapper(cityMapper);
|
|
const flightMapper = new FlightMapper(airlineMapper, airportMapper);
|
|
const hotelFacilityMapper = new HotelFacilityMapper();
|
|
const hotelMapper = new HotelMapper(cityMapper, hotelFacilityMapper);
|
|
const transportationMapper = new TransportationMapper();
|
|
const packageMapper = new PackageMapper(
|
|
flightMapper,
|
|
hotelMapper,
|
|
transportationMapper,
|
|
);
|
|
|
|
const countryRouter = new CountryController(countryMapper).buildRouter();
|
|
const cityRouter = new CityController(cityMapper).buildRouter();
|
|
const airlineRouter = new AirlineController(
|
|
airlineMapper,
|
|
this._fileStorage,
|
|
).buildRouter();
|
|
const airportRouter = new AirportController(airportMapper).buildRouter();
|
|
const flightRouter = new FlightController(flightMapper).buildRouter();
|
|
const hotelFacilityRouter = new HotelFacilityController(
|
|
hotelFacilityMapper,
|
|
).buildRouter();
|
|
const hotelRouter = new HotelController(
|
|
hotelMapper,
|
|
this._fileStorage,
|
|
).buildRouter();
|
|
const transportationRouter = new TransportationController(
|
|
transportationMapper,
|
|
this._fileStorage,
|
|
).buildRouter();
|
|
const packageRouter = new PackageController(
|
|
packageMapper,
|
|
this._fileStorage,
|
|
).buildRouter();
|
|
|
|
this._app.use("/countries", countryRouter);
|
|
this._app.use("/cities", cityRouter);
|
|
this._app.use("/airlines", airlineRouter);
|
|
this._app.use("/airports", airportRouter);
|
|
this._app.use("/flights", flightRouter);
|
|
this._app.use("/hotel-facilities", hotelFacilityRouter);
|
|
this._app.use("/hotels", hotelRouter);
|
|
this._app.use("/transportations", transportationRouter);
|
|
this._app.use("/packages", packageRouter);
|
|
}
|
|
|
|
public initializeErrorHandlers() {}
|
|
|
|
public run() {
|
|
const port = serverConfig.port;
|
|
const host = serverConfig.host;
|
|
|
|
this._app.listen(port, host, (err) => {
|
|
if (err) {
|
|
console.log(`Failed to listen server: ${err.message}`);
|
|
} else {
|
|
console.log(`Server listening at ${host}:${port}`);
|
|
}
|
|
});
|
|
}
|
|
}
|