38368-vm/backend/src/db/models/features.js
2026-02-12 00:18:45 +00:00

184 lines
2.4 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const features = sequelize.define(
'features',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
summary: {
type: DataTypes.TEXT,
},
priority: {
type: DataTypes.ENUM,
values: [
"low",
"medium",
"high",
"critical"
],
},
status: {
type: DataTypes.ENUM,
values: [
"backlog",
"in_progress",
"in_review",
"done",
"blocked"
],
},
due_at: {
type: DataTypes.DATE,
},
estimate_hours: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
features.associate = (db) => {
db.features.belongsToMany(db.users, {
as: 'watchers',
foreignKey: {
name: 'features_watchersId',
},
constraints: false,
through: 'featuresWatchersUsers',
});
db.features.belongsToMany(db.users, {
as: 'watchers_filter',
foreignKey: {
name: 'features_watchersId',
},
constraints: false,
through: 'featuresWatchersUsers',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.features.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: false,
});
db.features.belongsTo(db.users, {
as: 'assignee',
foreignKey: {
name: 'assigneeId',
},
constraints: false,
});
db.features.hasMany(db.file, {
as: 'spec_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.features.getTableName(),
belongsToColumn: 'spec_files',
},
});
db.features.belongsTo(db.users, {
as: 'createdBy',
});
db.features.belongsTo(db.users, {
as: 'updatedBy',
});
};
return features;
};