Files
vitfit-r2/V2/app/modules/org/model.js
T
2026-06-30 08:46:12 -04:00

58 lines
2.5 KiB
JavaScript

'use strict';
module.exports = (sequelize, DataTypes) => {
const Organization = sequelize.define('Organization', {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING, allowNull: false },
slug: { type: DataTypes.STRING, unique: true },
timezone: { type: DataTypes.STRING, defaultValue: 'UTC' },
features: {
type: DataTypes.TEXT,
defaultValue: '[]',
get() { try { return JSON.parse(this.getDataValue('features') || '[]'); } catch { return []; } },
set(v) { this.setDataValue('features', JSON.stringify(v)); },
},
isActive: { type: DataTypes.BOOLEAN, defaultValue: true },
licenseOwner: { type: DataTypes.STRING },
licenseEmail: { type: DataTypes.STRING },
});
Organization.beforeCreate(org => {
if (!org.slug) {
org.slug = org.name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
}
});
const Branding = sequelize.define('Branding', {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
organizationId: { type: DataTypes.INTEGER, allowNull: false, unique: true },
appName: { type: DataTypes.STRING, defaultValue: 'VitFit' },
logoPath: { type: DataTypes.STRING },
primaryColor: { type: DataTypes.STRING, defaultValue: '#00FF88' },
secondaryColor: { type: DataTypes.STRING, defaultValue: '#4488FF' },
workColor: { type: DataTypes.STRING, defaultValue: '#00FF88' },
restColor: { type: DataTypes.STRING, defaultValue: '#4488FF' },
moveColor: { type: DataTypes.STRING, defaultValue: '#FF4444' },
btnPrimaryBg: { type: DataTypes.STRING },
btnSecondaryBg: { type: DataTypes.STRING },
pageBg: { type: DataTypes.STRING },
popupBg: { type: DataTypes.STRING },
overlayColor: { type: DataTypes.STRING },
tabStyle: { type: DataTypes.STRING, defaultValue: 'underline' },
bannerBg: { type: DataTypes.STRING },
drawerBg: { type: DataTypes.STRING },
textPrimary: { type: DataTypes.STRING },
textSecondary: { type: DataTypes.STRING },
cardBg: { type: DataTypes.STRING },
inputBg: { type: DataTypes.STRING },
hoverBg: { type: DataTypes.STRING },
borderColor: { type: DataTypes.STRING },
});
Organization.associate = (models) => {
Organization.hasOne(models.Branding, { foreignKey: 'organizationId' });
};
return { Organization, Branding };
};