38255-vm/backend/src/db/models/publish_batches.js
2026-02-06 22:07:52 +00:00

138 lines
2.0 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 publish_batches = sequelize.define(
'publish_batches',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"publishing",
"published",
"failed"
],
},
started_at: {
type: DataTypes.DATE,
},
finished_at: {
type: DataTypes.DATE,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
publish_batches.associate = (db) => {
db.publish_batches.belongsToMany(db.content_items, {
as: 'content_items',
foreignKey: {
name: 'publish_batches_content_itemsId',
},
constraints: false,
through: 'publish_batchesContent_itemsContent_items',
});
db.publish_batches.belongsToMany(db.content_items, {
as: 'content_items_filter',
foreignKey: {
name: 'publish_batches_content_itemsId',
},
constraints: false,
through: 'publish_batchesContent_itemsContent_items',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.publish_batches.belongsTo(db.users, {
as: 'published_by_user',
foreignKey: {
name: 'published_by_userId',
},
constraints: false,
});
db.publish_batches.belongsTo(db.users, {
as: 'createdBy',
});
db.publish_batches.belongsTo(db.users, {
as: 'updatedBy',
});
};
return publish_batches;
};