38260-vm/backend/src/db/models/factions.js
2026-02-07 03:34:22 +00:00

144 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 factions = sequelize.define(
'factions',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
code: {
type: DataTypes.TEXT,
},
alignment: {
type: DataTypes.ENUM,
values: [
"friendly",
"hostile",
"neutral"
],
},
color_hex: {
type: DataTypes.TEXT,
},
emblem_url: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
factions.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.factions.hasMany(db.scenario_factions, {
as: 'scenario_factions_faction',
foreignKey: {
name: 'factionId',
},
constraints: false,
});
//end loop
db.factions.belongsTo(db.users, {
as: 'createdBy',
});
db.factions.belongsTo(db.users, {
as: 'updatedBy',
});
};
return factions;
};