Duffer Derek
import Sequelize from "sequelize";
import dbConnection from "../config/database.js";
import User from "./users.js";
import tasks from "./tasks.js";
import files from "./files.js";
import SharedTasks from "./sharedTasks.js";
import subTasksComments from "./subTasksComments.js";
const sequelize = dbConnection;
const subTasks = sequelize.define(
"sub_tasks",
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
item_id: {
type: Sequelize.BIGINT,
allowNull: true,
},
user_item_id: {
type: Sequelize.BIGINT,
allowNull: true,
},
notes: {
type: Sequelize.STRING(255),
allowNull: false,
},
date: {
type: Sequelize.DATE,
allowNull: false,
},
time: {
type: Sequelize.STRING(6),
allowNull: true,
},
is_holiday: {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 0,
},
shared_sub_task_time: {
type: Sequelize.STRING(6),
allowNull: true,
},
shared: {
type: Sequelize.BOOLEAN,
defaultValue: false,
},
shared_partner: {
type: Sequelize.JSON, // Use DataTypes.JSON for JSON data type
allowNull: true,
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
},
},
{
tableName: "sub_tasks",
timestamps: true, // Enable timestamps
updatedAt: "updated_at", // Customize the updatedAt column name
createdAt: "created_at", // Customize the createdAt column name
}
);
subTasks.belongsTo(User, { foreignKey: "user_item_id", targetKey: "item_id" });
User.hasMany(subTasks, { foreignKey: "user_item_id", sourceKey: "item_id" });
files.belongsTo(subTasks, {
foreignKey: "item_id",
as: "allFiles",
targetKey: "item_id",
});
subTasks.hasMany(files, {
foreignKey: "item_id", // files.item_id references subTasks.item_id
sourceKey: "item_id", // SubTasks.item_id
as: "allFiles", // Alias for the association
});
files.belongsTo(subTasks, {
as: "subtaskFiles",
foreignKey: "item_id",
targetKey: "id",
scope: {
keyword: "partner_image",
},
});
subTasks.hasMany(files, {
as: "subtaskFiles",
foreignKey: "item_id",
sourceKey: "id",
});
subTasks.belongsTo(SharedTasks, {
foreignKey: "item_id",
targetKey: "task_id",
});
SharedTasks.hasMany(subTasks, {
foreignKey: "item_id",
sourceKey: "task_id",
});
subTasks.hasMany(subTasksComments, { foreignKey: "sub_task_id" });
subTasksComments.belongsTo(subTasks, { foreignKey: "sub_task_id" });
export default subTasks;
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists