import type { CreationOptional, InferAttributes, InferCreationAttributes, Sequelize, } from "sequelize"; import { DataTypes, Model } from "sequelize"; export class CompanyModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare name: string; declare active: boolean; declare logoVersion: CreationOptional; } export class PersonModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare companyId: string; declare name: string; declare position: string | null; declare email: string | null; declare phone: string | null; declare isContact: boolean; declare active: boolean; declare photoVersion: CreationOptional; } export class SiteModel extends Model< InferAttributes, InferCreationAttributes > { declare id: string; declare companyId: string; declare name: string; declare address: string | null; } export function initializeCompanyModels(database: Sequelize): void { CompanyModel.init( { id: { type: DataTypes.UUID, primaryKey: true }, name: { type: DataTypes.STRING(100), allowNull: false }, active: { type: DataTypes.BOOLEAN, allowNull: false }, logoVersion: { type: DataTypes.STRING(64), allowNull: true }, }, { sequelize: database, tableName: "companies", timestamps: false } ); const childFields = { id: { type: DataTypes.UUID, primaryKey: true }, companyId: { type: DataTypes.UUID, allowNull: false }, name: { type: DataTypes.STRING(100), allowNull: false }, }; PersonModel.init( { ...childFields, position: { type: DataTypes.STRING(100), allowNull: true }, email: { type: DataTypes.STRING(254), allowNull: true }, phone: { type: DataTypes.STRING(50), allowNull: true }, isContact: { type: DataTypes.BOOLEAN, allowNull: false }, active: { type: DataTypes.BOOLEAN, allowNull: false }, photoVersion: { type: DataTypes.STRING(64), allowNull: true }, }, { sequelize: database, tableName: "company_contacts", timestamps: false } ); SiteModel.init( { ...childFields, address: { type: DataTypes.TEXT, allowNull: true } }, { sequelize: database, tableName: "company_sites", timestamps: false } ); }