metis-desk/modules/companies/src/api/infrastructure/persistence/people.model.ts
David 18324f92bd feat: add person and department management features
- Implemented Person entity with validation and update methods.
- Created CalendarDate value object for date validation.
- Developed migration script to transition company_contacts to person and department structures.
- Established Sequelize models for departments and assignments.
- Introduced request DTOs for person and department management.
- Added shared DTO schemas for validation.
- Built assignment and department forms with validation and submission handling.
- Created people section to manage and display company personnel.
- Implemented person form for adding and editing personnel details.
2026-10-03 13:13:15 +02:00

78 lines
2.6 KiB
TypeScript

import type { InferAttributes, InferCreationAttributes, Sequelize } from "sequelize";
import { DataTypes, Model } from "sequelize";
export class DepartmentModel extends Model<
InferAttributes<DepartmentModel>,
InferCreationAttributes<DepartmentModel>
> {
declare id: string;
declare companyId: string;
declare name: string;
declare nameKey: string;
declare active: boolean;
}
export class AssignmentModel extends Model<
InferAttributes<AssignmentModel>,
InferCreationAttributes<AssignmentModel>
> {
declare id: string;
declare companyId: string;
declare personId: string;
declare departmentId: string;
declare position: string | null;
declare startDate: string;
declare endDate: string | null;
declare isPrimary: boolean;
}
export class AssignmentRevisionModel extends Model<
InferAttributes<AssignmentRevisionModel>,
InferCreationAttributes<AssignmentRevisionModel>
> {
declare id: string;
declare assignmentId: string;
declare sequence: number;
declare position: string | null;
declare startDate: string;
declare endDate: string | null;
declare isPrimary: boolean;
declare recordedAt: string;
}
export const assignmentColumns = {
position: { type: DataTypes.STRING(100), allowNull: true },
startDate: { type: DataTypes.DATEONLY, allowNull: false },
endDate: { type: DataTypes.DATEONLY, allowNull: true },
isPrimary: { type: DataTypes.BOOLEAN, allowNull: false },
};
export function initializePeopleModels(database: Sequelize): void {
const key = { type: DataTypes.UUID, primaryKey: true };
DepartmentModel.init(
{
id: key,
companyId: { type: DataTypes.UUID, allowNull: false },
name: { type: DataTypes.STRING(100), allowNull: false },
nameKey: { type: DataTypes.STRING(200).BINARY, allowNull: false },
active: { type: DataTypes.BOOLEAN, allowNull: false },
},
{ sequelize: database, tableName: "company_departments", timestamps: false }
);
AssignmentModel.init(
{
id: key,
companyId: { type: DataTypes.UUID, allowNull: false },
personId: { type: DataTypes.UUID, allowNull: false },
departmentId: { type: DataTypes.UUID, allowNull: false },
...assignmentColumns,
},
{ sequelize: database, tableName: "person_department_assignments", timestamps: false }
);
AssignmentRevisionModel.init(
{
id: key,
assignmentId: { type: DataTypes.UUID, allowNull: false },
sequence: { type: DataTypes.INTEGER, allowNull: false },
...assignmentColumns,
recordedAt: { type: DataTypes.STRING(24), allowNull: false },
},
{ sequelize: database, tableName: "department_assignment_revisions", timestamps: false }
);
}