226 lines
8.9 KiB
TypeScript
226 lines
8.9 KiB
TypeScript
import type { AbstractEmailService } from "@/common/services/email-service/abstract.email-service";
|
|
import { LibraryEmailService } from "@/common/services/email-service/library.email-service";
|
|
import type { AbstractFileStorage } from "@/common/services/file-storage/abstract.file-storage";
|
|
import { LocalFileStorage } from "@/common/services/file-storage/local.file-storage";
|
|
import type { AbstractJwtService } from "@/common/services/jwt-service/abstract.jwt-service";
|
|
import { LibraryJwtService } from "@/common/services/jwt-service/library.jwt-service";
|
|
import type { AbstractPaymentService } from "@/common/services/payment-service/abstract.payment-service";
|
|
import { MidtransPaymentService } from "@/common/services/payment-service/midtrans.payment-service";
|
|
import type { AbstractWhatsAppService } from "@/common/services/whatsapp-service/abstract.whatsapp-service";
|
|
import { MetaWhatsAppService } from "@/common/services/whatsapp-service/meta.whatsapp-service";
|
|
import { serverConfig } from "@/configs/server.config";
|
|
import { AdminController } from "@/modules/admin/admin.controller";
|
|
import { AdminMapper } from "@/modules/admin/admin.mapper";
|
|
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 { ArticleController } from "@/modules/article/article.controller";
|
|
import { ArticleMapper } from "@/modules/article/article.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 { FlightClassController } from "@/modules/flight-class/flight-class.controller";
|
|
import { FlightClassMapper } from "@/modules/flight-class/flight-class.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 { OrderController } from "@/modules/order/order.controller";
|
|
import { OrderMapper } from "@/modules/order/order.mapper";
|
|
import { PackageController } from "@/modules/package/package.controller";
|
|
import { PackageMapper } from "@/modules/package/package.mapper";
|
|
import { PartnerController } from "@/modules/partner/partner.controller";
|
|
import { PartnerMapper } from "@/modules/partner/partner.mapper";
|
|
import { StaticController } from "@/modules/static/static.controller";
|
|
import { TagController } from "@/modules/tag/tag.controller";
|
|
import { TagMapper } from "@/modules/tag/tag.mapper";
|
|
import { TestimonyController } from "@/modules/testimony/testimony.controller";
|
|
import { TestimonyMapper } from "@/modules/testimony/testimony.mapper";
|
|
import { TransportationClassController } from "@/modules/transportation-class/transportation-class.controller";
|
|
import { TransportationClassMapper } from "@/modules/transportation-class/transportation-class.mapper";
|
|
import { TransportationController } from "@/modules/transportation/transportation.controller";
|
|
import { TransportationMapper } from "@/modules/transportation/transportation.mapper";
|
|
import { WhatsAppController } from "@/modules/whatsapp/whatsapp.controller";
|
|
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 _emailService!: AbstractEmailService;
|
|
private _fileStorage!: AbstractFileStorage;
|
|
private _jwtService!: AbstractJwtService;
|
|
private _paymentService!: AbstractPaymentService;
|
|
private _whatsAppService!: AbstractWhatsAppService;
|
|
|
|
public constructor() {
|
|
this._app = express();
|
|
}
|
|
|
|
public initializeServices() {
|
|
this._emailService = new LibraryEmailService();
|
|
this._fileStorage = new LocalFileStorage();
|
|
this._jwtService = new LibraryJwtService();
|
|
this._paymentService = new MidtransPaymentService();
|
|
this._whatsAppService = new MetaWhatsAppService();
|
|
}
|
|
|
|
public initializeMiddlewares() {
|
|
this._app.use(helmet());
|
|
this._app.use(cors());
|
|
this._app.use(compression());
|
|
this._app.use(express.json({ limit: "100mb" }));
|
|
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 flightClassMapper = new FlightClassMapper(flightMapper);
|
|
const hotelFacilityMapper = new HotelFacilityMapper();
|
|
const hotelMapper = new HotelMapper(cityMapper, hotelFacilityMapper);
|
|
const transportationMapper = new TransportationMapper();
|
|
const transportationClassMapper = new TransportationClassMapper(
|
|
transportationMapper,
|
|
);
|
|
const partnerMapper = new PartnerMapper();
|
|
const packageMapper = new PackageMapper(
|
|
partnerMapper,
|
|
flightMapper,
|
|
hotelMapper,
|
|
transportationMapper,
|
|
);
|
|
const adminMapper = new AdminMapper();
|
|
const orderMapper = new OrderMapper(packageMapper, partnerMapper);
|
|
const testimonyMapper = new TestimonyMapper();
|
|
const tagMapper = new TagMapper();
|
|
const articleMapper = new ArticleMapper(tagMapper);
|
|
|
|
const countryRouter = new CountryController(
|
|
countryMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const cityRouter = new CityController(
|
|
cityMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const airlineRouter = new AirlineController(
|
|
airlineMapper,
|
|
this._fileStorage,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const airportRouter = new AirportController(
|
|
airportMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const flightRouter = new FlightController(
|
|
flightMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const flightClassRouter = new FlightClassController(
|
|
flightClassMapper,
|
|
).buildRouter();
|
|
const hotelFacilityRouter = new HotelFacilityController(
|
|
hotelFacilityMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const hotelRouter = new HotelController(
|
|
hotelMapper,
|
|
this._fileStorage,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const transportationRouter = new TransportationController(
|
|
transportationMapper,
|
|
this._fileStorage,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const transportationClassRouter = new TransportationClassController(
|
|
transportationClassMapper,
|
|
).buildRouter();
|
|
const packageRouter = new PackageController(
|
|
packageMapper,
|
|
this._fileStorage,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const adminRouter = new AdminController(
|
|
adminMapper,
|
|
this._fileStorage,
|
|
this._emailService,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const partnerRouter = new PartnerController(
|
|
partnerMapper,
|
|
this._fileStorage,
|
|
this._emailService,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const orderRouter = new OrderController(
|
|
orderMapper,
|
|
this._paymentService,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const staticRouter = new StaticController(this._fileStorage).buildRouter();
|
|
const whatsAppRouter = new WhatsAppController(
|
|
this._whatsAppService,
|
|
).buildRouter();
|
|
const testimonyRouter = new TestimonyController(
|
|
testimonyMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const tagRouter = new TagController(
|
|
tagMapper,
|
|
this._jwtService,
|
|
).buildRouter();
|
|
const articleRouter = new ArticleController(
|
|
articleMapper,
|
|
this._fileStorage,
|
|
this._jwtService,
|
|
).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("/flight-classes", flightClassRouter);
|
|
this._app.use("/hotel-facilities", hotelFacilityRouter);
|
|
this._app.use("/hotels", hotelRouter);
|
|
this._app.use("/transportations", transportationRouter);
|
|
this._app.use("/transportation-classes", transportationClassRouter);
|
|
this._app.use("/packages", packageRouter);
|
|
this._app.use("/admins", adminRouter);
|
|
this._app.use("/partners", partnerRouter);
|
|
this._app.use("/orders", orderRouter);
|
|
this._app.use("/statics", staticRouter);
|
|
this._app.use("/whatsapp", whatsAppRouter);
|
|
this._app.use("/testimonies", testimonyRouter);
|
|
this._app.use("/tags", tagRouter);
|
|
this._app.use("/articles", articleRouter);
|
|
}
|
|
|
|
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}`);
|
|
}
|
|
});
|
|
}
|
|
}
|