require("express-async-errors");

const express = require("express");
const cors = require("cors");

const usersRoute = require("./modules/users/users.routes");
const db = require("./managers/dbConfig");
const errorHandler = require("./handlers/errorHandler");
const systemAdminRoute = require("./modules/administratives/sysadmin.routes");
const licenseRoutes = require("./modules/license/license.routes");

port = process.env.PORT;

const app = express();
app.use(cors());

db.getConnection()
  .then(() => {
    console.log("Successfully Connected to Database");
  })
  .catch((e) => {
    console.log(`Error connecting to Database: ${e}`);
  });

app.use(express.json());

app.use("/api/users", usersRoute);
app.use("/api/alakoso", systemAdminRoute);
app.use("/api/license", licenseRoutes);
app.use(errorHandler);

app.listen(port, () => {
  console.log(`App is listening on port: ${port}`);
});
