38389-vm/backend/src/db/models/church_yearly_metrics.js
2026-02-13 00:57:45 +00:00

142 lines
1.9 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 church_yearly_metrics = sequelize.define(
'church_yearly_metrics',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
year: {
type: DataTypes.INTEGER,
},
average_weekly_attendance: {
type: DataTypes.INTEGER,
},
membership_count: {
type: DataTypes.INTEGER,
},
faith_decisions_count: {
type: DataTypes.INTEGER,
},
ordained_preachers_count: {
type: DataTypes.INTEGER,
},
non_ordained_preachers_count: {
type: DataTypes.INTEGER,
},
ordained_deacons_count: {
type: DataTypes.INTEGER,
},
non_ordained_deacons_count: {
type: DataTypes.INTEGER,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
church_yearly_metrics.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.church_yearly_metrics.belongsTo(db.churches, {
as: 'church',
foreignKey: {
name: 'churchId',
},
constraints: false,
});
db.church_yearly_metrics.belongsTo(db.users, {
as: 'createdBy',
});
db.church_yearly_metrics.belongsTo(db.users, {
as: 'updatedBy',
});
};
return church_yearly_metrics;
};