39313-vm/backend/src/db/models/staff_service_assignments.js
2026-03-25 14:25:52 +00:00

112 lines
1.7 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_service_assignments = sequelize.define(
'staff_service_assignments',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
duration_override_minutes: {
type: DataTypes.INTEGER,
},
price_override: {
type: DataTypes.DECIMAL,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
staff_service_assignments.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.staff_service_assignments.belongsTo(db.staff_members, {
as: 'staff_member',
foreignKey: {
name: 'staff_memberId',
},
constraints: false,
});
db.staff_service_assignments.belongsTo(db.services, {
as: 'service',
foreignKey: {
name: 'serviceId',
},
constraints: false,
});
db.staff_service_assignments.belongsTo(db.users, {
as: 'createdBy',
});
db.staff_service_assignments.belongsTo(db.users, {
as: 'updatedBy',
});
};
return staff_service_assignments;
};