151 lines
2.3 KiB
JavaScript
151 lines
2.3 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 experts = sequelize.define(
|
|
'experts',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
full_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
title: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
bio: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
rating: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
experience_years: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
experts.associate = (db) => {
|
|
|
|
db.experts.belongsToMany(db.services, {
|
|
as: 'specialties',
|
|
foreignKey: {
|
|
name: 'experts_specialtiesId',
|
|
},
|
|
constraints: false,
|
|
through: 'expertsSpecialtiesServices',
|
|
});
|
|
|
|
db.experts.belongsToMany(db.services, {
|
|
as: 'specialties_filter',
|
|
foreignKey: {
|
|
name: 'experts_specialtiesId',
|
|
},
|
|
constraints: false,
|
|
through: 'expertsSpecialtiesServices',
|
|
});
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.experts.hasMany(db.sessions, {
|
|
as: 'sessions_expert',
|
|
foreignKey: {
|
|
name: 'expertId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.experts.belongsTo(db.organizations, {
|
|
as: 'organization',
|
|
foreignKey: {
|
|
name: 'organizationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
db.experts.hasMany(db.file, {
|
|
as: 'avatar',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.experts.getTableName(),
|
|
belongsToColumn: 'avatar',
|
|
},
|
|
});
|
|
|
|
|
|
db.experts.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.experts.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return experts;
|
|
};
|
|
|
|
|