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/tasks.js

import Sequelize from "sequelize";
import User from "./users.js";
import subTasks from "./subTasks.js";
import dbConnection from "../config/database.js";
import files from "./files.js";
import SharedTasks from "./sharedTasks.js";

const sequelize = dbConnection;

const tasks = sequelize.define(
  "tasks",
  {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER,
    },
    item_id: {
      type: Sequelize.BIGINT,
      allowNull: false,
    },
    user_item_id: {
      type: Sequelize.BIGINT,
      allowNull: true,
    },
    service_manager_id: {
      type: Sequelize.BIGINT,
      allowNull: true,
      defaultValue: 0,
    },
    customer_first_name: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    customer_last_name: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    customer_phone_number: {
      type: Sequelize.STRING(20),
      allowNull: true,
    },
    customer_address: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    type: {
      type: Sequelize.TINYINT,
      allowNull: true,
    },
    status: {
      type: Sequelize.TINYINT,
      allowNull: true,
      defaultValue: 1,
      comment:
        "1=Oprettet, 3=Fuldført ,4=Faktureret, 5=Annulleret Maler ,6=Booket 8=Annulleret Kunden,",
    },
    start_date: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    end_date: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    price: {
      type: Sequelize.FLOAT,
      allowNull: true,
    },
    invoice_description: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    extra_services: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    free_text_for_additional_services: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    not_included_price: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    without_calculation: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    internal_notes: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    internal_notes_to_admin: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    further_description_for_painting_is_displayed_on_pdf: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    countryside: {
      type: Sequelize.TINYINT,
      allowNull: true,
    },
    country_side_color: {
      type: Sequelize.STRING(20),
      allowNull: true,
    },
    housing_type: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    customer_email: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    customer_has_paid: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    subcontractor_has_paid: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    product_type: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    estimated_material_usage: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    next_sms_date_for_partners: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    sms_time_for_customer: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    final_deadline_date: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    paid_amount_to_painter: {
      type: Sequelize.DECIMAL(10, 2),
      allowNull: true,
    },
    add_product: {
      type: Sequelize.BIGINT,
      allowNull: true,
    },
    estimated_task_time: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    hours_used: {
      type: Sequelize.DECIMAL(10, 2),
      allowNull: true,
    },
    materials_incl_vat: {
      type: Sequelize.DECIMAL(10, 2),
      allowNull: true,
    },
    create_partner_description: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    task_performed_by: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    mk_standard_offer_price: {
      type: Sequelize.DECIMAL(10, 2),
      allowNull: true,
    },
    mk_standard_offer_price_text: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    generate_pdf: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    confirmation_email: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    expected_arrival_hour: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    expected_arrival_minute: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    send_sms: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    painterkanon_inquiry_offer: {
      type: Sequelize.BIGINT,
      allowNull: true,
    },
    floor_cannon: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    short_complaint_link: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    send_complaint_images_to_painter: {
      type: Sequelize.STRING(250),
      allowNull: true,
    },
    order_comment: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    material_pickup_date: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    delivery_address: {
      type: Sequelize.STRING(255),
      allowNull: true,
    },
    order_id: {
      type: Sequelize.JSON,
      allowNull: true,
    },
    painter_name_picking_up: {
      type: Sequelize.TEXT,
      allowNull: true,
    },
    material_order: {
      type: Sequelize.STRING(150),
      allowNull: true,
    },
    misc_expenses: {
      type: Sequelize.DECIMAL(10, 2),
      allowNull: true,
    },
    employee_salary_cost_percent: {
      type: Sequelize.JSON,
      allowNull: true,
    },
    date_start: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    date_end: {
      type: Sequelize.DATE,
      allowNull: true,
    },
    office_partner: {
      type: Sequelize.BIGINT,
      allowNull: true,
      defaultValue: null,
    },
    created_at: {
      allowNull: false,
      type: Sequelize.DATE,
    },
    updated_at: {
      allowNull: false,
      type: Sequelize.DATE,
    },
  },
  {
    tableName: "tasks",
    timestamps: true, // Enable timestamps
    updatedAt: "updated_at", // Customize the updatedAt column name
    createdAt: "created_at", // Customize the createdAt column name
  }
);

// Define associations
tasks.belongsTo(User, { foreignKey: "user_item_id", targetKey: "item_id" });
User.hasMany(tasks, { foreignKey: "user_item_id", sourceKey: "item_id" });
subTasks.belongsTo(tasks, { foreignKey: "item_id", targetKey: "item_id" });
tasks.hasMany(subTasks, { foreignKey: "item_id", sourceKey: "item_id" });
files.belongsTo(tasks, { foreignKey: "item_id", targetKey: "item_id" });
tasks.hasMany(files, { foreignKey: "item_id", sourceKey: "item_id" });
SharedTasks.belongsTo(tasks, { foreignKey: "task_id", targetKey: "item_id" });
tasks.hasMany(SharedTasks, { foreignKey: "task_id", sourceKey: "item_id" });

// Add the association between Task and User based on service_manager_id
tasks.belongsTo(User, {
  as: "serviceManager",
  foreignKey: "service_manager_id",
  targetKey: "item_id",
});

export default tasks;

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