Duffer Derek

Current Path : /var/www/api-mk-planner.bitkit.dk/httpdocs/Backend/src/database/models/
Upload File :
Current File : /var/www/api-mk-planner.bitkit.dk/httpdocs/Backend/src/database/models/employee_leaves.js

import Sequelize from "sequelize";
import dbConnection from "../config/database.js";
import User from "./users.js";

const sequelize = dbConnection;

const EmployeeLeaves = sequelize.define(
  "employee_leaves",
  {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER,
    },
    item_id: {
      type: Sequelize.BIGINT,
      allowNull: false,
    },
    user_item_id: {
      type: Sequelize.BIGINT,
      allowNull: false,
    },
    start_date: {
      type: Sequelize.DATE,
      allowNull: false,
    },
    end_date: {
      type: Sequelize.DATE,
      allowNull: false,
    },
    status: {
      type: Sequelize.TINYINT,
      allowNull: false,
      defaultValue: 0, //1-pending // 2- approved //3- decliened
    },
    created_at: {
      allowNull: false,
      type: Sequelize.DATE,
    },
    updated_at: {
      allowNull: false,
      type: Sequelize.DATE,
    },
  },
  {
    tableName: "employee_leaves",
    timestamps: true,
    updatedAt: "updated_at",
    createdAt: "created_at",
  }
);

// Add the association between Leaves and User based on user_item_id
EmployeeLeaves.belongsTo(User, {
  foreignKey: "user_item_id",
  targetKey: "item_id",
});
User.hasMany(EmployeeLeaves, {
  foreignKey: "user_item_id",
  sourceKey: "item_id",
});

export default EmployeeLeaves;

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists