38264-vm/backend/src/db/models/soldier_allowances.js
2026-02-07 08:01:51 +00:00

137 lines
1.8 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 soldier_allowances = sequelize.define(
'soldier_allowances',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
amount_cdf: {
type: DataTypes.DECIMAL,
},
percentage: {
type: DataTypes.DECIMAL,
},
effective_from: {
type: DataTypes.DATE,
},
effective_to: {
type: DataTypes.DATE,
},
active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
soldier_allowances.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.soldier_allowances.belongsTo(db.soldiers, {
as: 'soldier',
foreignKey: {
name: 'soldierId',
},
constraints: false,
});
db.soldier_allowances.belongsTo(db.allowance_types, {
as: 'allowance_type',
foreignKey: {
name: 'allowance_typeId',
},
constraints: false,
});
db.soldier_allowances.belongsTo(db.users, {
as: 'createdBy',
});
db.soldier_allowances.belongsTo(db.users, {
as: 'updatedBy',
});
};
return soldier_allowances;
};