metis-desk/modules/companies/src/api/infrastructure/persistence/configuration-snapshots.ts

162 lines
5.7 KiB
TypeScript
Raw Normal View History

2026-10-10 11:32:40 +00:00
import { DataTypes } from "sequelize";
import { ApplicationConfigurationInputSchema } from "../../domain/application-configuration-values";
import { CertificateConfigurationInputSchema } from "../../domain/certificate-configuration-values";
import { FolderMappingInputSchema } from "../../domain/folder-mapping-values";
import { PrinterConfigurationInputSchema } from "../../domain/printer-configuration-values";
import { TeleworkAuthorizationInputSchema } from "../../domain/telework-authorization-values";
import { WorkProfileInputSchema } from "../../domain/work-profile-values";
import type { SnapshotDefinition } from "./scalar-snapshot-normalization";
export const profileSnapshot = {
schema: WorkProfileInputSchema,
columns: {
name: { type: DataTypes.STRING(100), allowNull: false },
personId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "company_contacts", key: "id" },
onDelete: "RESTRICT",
},
assetId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "assets", key: "id" },
onDelete: "RESTRICT",
},
accountId: {
type: DataTypes.UUID,
allowNull: true,
references: { model: "access_items", key: "id" },
onDelete: "RESTRICT",
},
active: { type: DataTypes.BOOLEAN, allowNull: false },
notes: { type: DataTypes.TEXT, allowNull: true },
},
booleans: ["active"],
} satisfies SnapshotDefinition<ReturnType<typeof WorkProfileInputSchema.parse>>;
export const teleworkSnapshot = {
schema: TeleworkAuthorizationInputSchema,
columns: {
personId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "company_contacts", key: "id" },
onDelete: "RESTRICT",
},
active: { type: DataTypes.BOOLEAN, allowNull: false },
startsOn: { type: DataTypes.STRING(10), allowNull: true },
expiresOn: { type: DataTypes.STRING(10), allowNull: true },
notes: { type: DataTypes.TEXT, allowNull: true },
},
booleans: ["active"],
} satisfies SnapshotDefinition<ReturnType<typeof TeleworkAuthorizationInputSchema.parse>>;
export const applicationSnapshot = {
schema: ApplicationConfigurationInputSchema,
columns: {
profileId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "work_profiles", key: "id" },
onDelete: "RESTRICT",
},
resourceId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "resources", key: "id" },
onDelete: "RESTRICT",
},
delivery: { type: DataTypes.STRING(16), allowNull: false },
version: { type: DataTypes.STRING(100), allowNull: true },
state: { type: DataTypes.STRING(20), allowNull: false },
notes: { type: DataTypes.TEXT, allowNull: true },
},
booleans: [],
} satisfies SnapshotDefinition<ReturnType<typeof ApplicationConfigurationInputSchema.parse>>;
export const certificateSnapshot = {
schema: CertificateConfigurationInputSchema,
columns: {
profileId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "work_profiles", key: "id" },
onDelete: "RESTRICT",
},
resourceId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "resources", key: "id" },
onDelete: "RESTRICT",
},
location: { type: DataTypes.STRING(255), allowNull: true },
state: { type: DataTypes.STRING(20), allowNull: false },
notes: { type: DataTypes.TEXT, allowNull: true },
},
booleans: [],
} satisfies SnapshotDefinition<ReturnType<typeof CertificateConfigurationInputSchema.parse>>;
export const printerSnapshot = {
schema: PrinterConfigurationInputSchema,
columns: {
profileId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "work_profiles", key: "id" },
onDelete: "RESTRICT",
},
printerId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "assets", key: "id" },
onDelete: "RESTRICT",
},
connection: { type: DataTypes.STRING(16), allowNull: false },
isDefault: { type: DataTypes.BOOLEAN, allowNull: false },
state: { type: DataTypes.STRING(20), allowNull: false },
notes: { type: DataTypes.TEXT, allowNull: true },
},
booleans: ["isDefault"],
} satisfies SnapshotDefinition<ReturnType<typeof PrinterConfigurationInputSchema.parse>>;
export const folderSnapshot = {
schema: FolderMappingInputSchema,
columns: {
profileId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "work_profiles", key: "id" },
onDelete: "RESTRICT",
},
needId: {
type: DataTypes.UUID,
allowNull: false,
references: { model: "access_items", key: "id" },
onDelete: "RESTRICT",
},
path: { type: DataTypes.STRING(255), allowNull: false },
driveLetter: { type: DataTypes.STRING(2), allowNull: true },
state: { type: DataTypes.STRING(20), allowNull: false },
notes: { type: DataTypes.TEXT, allowNull: true },
},
booleans: [],
} satisfies SnapshotDefinition<ReturnType<typeof FolderMappingInputSchema.parse>>;
export const configurationSnapshots = new Map<string, SnapshotDefinition<unknown>>([
["work_profiles", profileSnapshot],
["work_profile_revisions", profileSnapshot],
["telework_authorizations", teleworkSnapshot],
["telework_authorization_revisions", teleworkSnapshot],
["application_configurations", applicationSnapshot],
["application_configuration_revisions", applicationSnapshot],
["certificate_configurations", certificateSnapshot],
["certificate_configuration_revisions", certificateSnapshot],
["printer_configurations", printerSnapshot],
["printer_configuration_revisions", printerSnapshot],
["folder_mappings", folderSnapshot],
["folder_mapping_revisions", folderSnapshot],
]);