Skip to content

Job board web application made in fullstack JavaScript (PERN)

Notifications You must be signed in to change notification settings

glopez-dev/job_board

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Epitech 5th semester - Web module 01 - Job Board

Module: T-WEB-501

Overview

This project aims to realise the following :

  • A database to store job advertisements;

  • A webpage (front end) using Javascript technologies to display an online job advertise- ments board as well as an administration page for the admin user ;

  • An API (back end):

  • To allow users to apply for jobs ;

  • To manage the DB (only for admin user) with CRUD operations.

Step 01 - Creation of the SQL Database

We made the architecture using the MERISE method, a french method for data modelisation.

Conceptual Data Model :

🇫🇷 Modèle Conceptuel de Données (MCD)

This schema is very similar to the UML Entity / Relationship diagram.

jobboard2

Logic Model of Relational Data :

The MCD is converted to the Logic Model of Relational Data

🇫🇷 Modèle Logique de Données Relationelles (MLDR)

  • ADVERTISEMENT (idadvertisement, title, description, location, locationPostalCode, salary, datePosted, #idcompany, #id_people)
  • COMPANY (id_company, name, sector, location)
  • JOB_APPLICATION (idapplication, applicationDate, status, #idpeople 1, #id_people 2, #id_advertisement)
  • MAIL (idmail, subject, message, sendDate, #idpeople 1, #id_people 2, #id_application)
  • PEOPLE (idpeople, firstName, lastName, email, password, phone, #idcompany)

Physical Model of Data

Finally the MLDR is transcripted to a SQL script to create the database.

Script: create_database.sql

Step 02 - Creation of the advertisments page

Step 03 - Creation of the "learn more" button

Step 04 - Creation of a CRUD API

We chose to create the API with the framework Express.js, as we were using a MySQL database, we used the ORM Sequelize to interact with it.

Setting up the backend :

  • Configuration of the database access with Sequelize in the database.js file.
const { Sequelize } = require("sequelize");
const dotenv = require("dotenv");

dotenv.config();

const database = process.env.MYSQL_DATABASE;
const username = process.env.MYSQL_USERNAME;
const password = process.env.MYSQL_PASSWORD;
const host = process.env.MYSQL_HOST;

if (!username || !password || !host) {
  console.error("Certaines variables d'environnement ne sont pas définies.");
  process.exit(1);
}

const options = { dialect: "mysql", host: host };
const sequelize = new Sequelize(database, username, password, options, {
  logging: false,
});

sequelize
  .authenticate()
  .then(() => {
    console.log("Sucessfully connected to DB");
  })
  .catch((err) => {
    console.error("Error while connecting to DB : ", err);
  });

module.exports = sequelize;
  • Defining the ORM models representing our database schema in the models/ directory.
const { Sequelize, DataTypes } = require("sequelize");
const sequelize = require("../database.js");
const Company = require("./companyModel.js");
const People = require("./peopleModel.js");

const Advertisement = sequelize.define("Advertisement", {
  id_advertisement: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  title: DataTypes.STRING(100),
  description: DataTypes.JSON,
  location: DataTypes.STRING(100),
  location_postal_code: DataTypes.SMALLINT,
  salary: DataTypes.DECIMAL(10, 2),
  date_posted: DataTypes.DATE,
  contract_type: DataTypes.STRING(3),
});

Advertisement.belongsTo(Company, { foreignKey: "company_id" });
Advertisement.belongsTo(People, {
  as: "recruiter",
  foreignKey: "recruiter_id",
});

module.exports = Advertisement;
  • Importing these models and synchronizing them to the DB in the app.js file.
const Advertisement = require("./models/advertisementModel.js");
const People = require("./models/peopleModel.js");
const Company = require("./models/companyModel.js");
const JobApplication = require("./models/jobApplicationModel.js");
const Mail = require("./models/mailModel.js");

sequelize
  .sync()
  .then(() => {
    console.log(
      `[database.js] Sequelize models successfully synchronized with database "${process.env.MYSQL_DATABASE}".`
    );
  })
  .catch((err) => {
    console.error(
      "Error while synchronizing Sequelize models to the database :",
      err
    );
  });
  • Mounting all the neccessary middlewares on the express app instance in the app.js file.
const app = express();

app.use(morgan("tiny"));

app.use(express.json());

// The models routes are defined in routers in separate files
const advertisementsRoutes = require("./routes/advertisementRoutes.js");
// The routers are mounted as classic middlewares
app.use("/advertisements", advertisementsRoutes);
  • Using the express app instance to create the server in the server.js file.
const http = require("http");
const app = require("./app");

app.set("port", process.env.PORT || 3000);
const server = http.createServer(app);

server.listen(process.env.PORT || 3000);

About

Job board web application made in fullstack JavaScript (PERN)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published