273 lines
3.9 KiB
JavaScript
273 lines
3.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 tax_profiles = sequelize.define(
|
|
'tax_profiles',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
tax_year: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
federal_state: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"BW",
|
|
|
|
|
|
"BY",
|
|
|
|
|
|
"BE",
|
|
|
|
|
|
"BB",
|
|
|
|
|
|
"HB",
|
|
|
|
|
|
"HH",
|
|
|
|
|
|
"HE",
|
|
|
|
|
|
"MV",
|
|
|
|
|
|
"NI",
|
|
|
|
|
|
"NW",
|
|
|
|
|
|
"RP",
|
|
|
|
|
|
"SL",
|
|
|
|
|
|
"SN",
|
|
|
|
|
|
"ST",
|
|
|
|
|
|
"SH",
|
|
|
|
|
|
"TH"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
assessment_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"einzel",
|
|
|
|
|
|
"zusammen"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
profile_title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
disclaimer_acknowledged_text: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
disclaimer_acknowledged: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
last_reviewed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
tax_profiles.associate = (db) => {
|
|
|
|
db.tax_profiles.belongsToMany(db.household_members, {
|
|
as: 'household_members',
|
|
foreignKey: {
|
|
name: 'tax_profiles_household_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'tax_profilesHousehold_membersHousehold_members',
|
|
});
|
|
|
|
db.tax_profiles.belongsToMany(db.household_members, {
|
|
as: 'household_members_filter',
|
|
foreignKey: {
|
|
name: 'tax_profiles_household_membersId',
|
|
},
|
|
constraints: false,
|
|
through: 'tax_profilesHousehold_membersHousehold_members',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.tax_profiles.hasMany(db.settings, {
|
|
as: 'settings_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.household_members, {
|
|
as: 'household_members_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.employers, {
|
|
as: 'employers_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.income_entries, {
|
|
as: 'income_entries_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.deduction_entries, {
|
|
as: 'deduction_entries_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.receipts, {
|
|
as: 'receipts_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.wizard_checkpoints, {
|
|
as: 'wizard_checkpoints_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.tax_profiles.hasMany(db.audit_events, {
|
|
as: 'audit_events_tax_profile',
|
|
foreignKey: {
|
|
name: 'tax_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.tax_profiles.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.tax_profiles.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.tax_profiles.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return tax_profiles;
|
|
};
|
|
|
|
|