156 lines
2.6 KiB
JavaScript
156 lines
2.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 staff_profiles = sequelize.define(
|
|
'staff_profiles',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
display_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
bio: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_bookable: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
staff_profiles.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.staff_profiles.hasMany(db.staff_service_assignments, {
|
|
as: 'staff_service_assignments_staff_profile',
|
|
foreignKey: {
|
|
name: 'staff_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.staff_profiles.hasMany(db.availability_rules, {
|
|
as: 'availability_rules_staff_profile',
|
|
foreignKey: {
|
|
name: 'staff_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.staff_profiles.hasMany(db.time_off_blocks, {
|
|
as: 'time_off_blocks_staff_profile',
|
|
foreignKey: {
|
|
name: 'staff_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_profiles.hasMany(db.bookings, {
|
|
as: 'bookings_staff_profile',
|
|
foreignKey: {
|
|
name: 'staff_profileId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.staff_profiles.belongsTo(db.users, {
|
|
as: 'user',
|
|
foreignKey: {
|
|
name: 'userId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.staff_profiles.belongsTo(db.locations, {
|
|
as: 'primary_location',
|
|
foreignKey: {
|
|
name: 'primary_locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.staff_profiles.hasMany(db.file, {
|
|
as: 'avatar',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.staff_profiles.getTableName(),
|
|
belongsToColumn: 'avatar',
|
|
},
|
|
});
|
|
|
|
|
|
db.staff_profiles.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.staff_profiles.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return staff_profiles;
|
|
};
|
|
|
|
|