182 lines
2.4 KiB
JavaScript
182 lines
2.4 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 people = sequelize.define(
|
|
'people',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
full_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
birth_date: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
role: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"person_1",
|
|
|
|
|
|
"person_2",
|
|
|
|
|
|
"kind",
|
|
|
|
|
|
"sonstige"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
occupation: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
tax_class: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
commute_distance_km: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
workdays_per_year: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
homeoffice_days: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
people.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.people.hasMany(db.employers, {
|
|
as: 'employers_person',
|
|
foreignKey: {
|
|
name: 'personId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.people.hasMany(db.income_statements, {
|
|
as: 'income_statements_person',
|
|
foreignKey: {
|
|
name: 'personId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.people.hasMany(db.expense_items, {
|
|
as: 'expense_items_person',
|
|
foreignKey: {
|
|
name: 'personId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.people.hasMany(db.receipts, {
|
|
as: 'receipts_person',
|
|
foreignKey: {
|
|
name: 'personId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.people.belongsTo(db.tax_profiles, {
|
|
as: 'tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.people.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.people.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return people;
|
|
};
|
|
|
|
|