38360-vm/backend/src/db/models/thread_subscriptions.js
2026-02-11 12:29:50 +00:00

110 lines
1.6 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 thread_subscriptions = sequelize.define(
'thread_subscriptions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
is_muted: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
subscribed_at: {
type: DataTypes.DATE,
},
last_notified_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
thread_subscriptions.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.thread_subscriptions.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.thread_subscriptions.belongsTo(db.threads, {
as: 'thread',
foreignKey: {
name: 'threadId',
},
constraints: false,
});
db.thread_subscriptions.belongsTo(db.users, {
as: 'createdBy',
});
db.thread_subscriptions.belongsTo(db.users, {
as: 'updatedBy',
});
};
return thread_subscriptions;
};