import { defaultGqlPermission, defaultPermission } from "@tailor-platform/erp-kit/core"; import { db } from "@tailor-platform/sdk"; import { position } from "./position"; import { workerEmployment } from "./workerEmployment"; const builtins = () => { return { // Intra-module FK: Assignment belongs to exactly one WorkerEmployment workerEmploymentId: db .uuid() .relation({ type: "n-1", toward: { type: workerEmployment, as: "workerEmployment" }, backward: "assignments", }) .description("Foreign key to the WorkerEmployment being posted"), // Intra-module FK: Assignment occupies exactly one Position positionId: db .uuid() .relation({ type: "n-1", toward: { type: position, as: "position" }, backward: "assignments", }) .description("Foreign key to the Position occupied (resolves Department, Site, JobProfile)"), // Primary vs concurrent/backup flag: at most one open primary Assignment per employment at any date isPrimary: db .bool() .description( "Whether this is the employment's primary post; concurrent assignments are non-primary", ), // Effective-dating per ADR-013: generation series effectiveStart: db.date().description("Date this Assignment generation becomes effective"), effectiveEnd: db .date({ optional: true }) .description( "Date this Assignment generation stops being effective; null means the current generation", ), versionOf: db .uuid() .description("Stable key binding together all generations of one continuous post assignment"), }; }; // Assignment is an internal effective-dated record; consumers do not extend it, so no custom-field slot. export function createAssignmentType() { return db .table("Assignment", { ...builtins(), ...db.fields.timestamps(), }) .permission(defaultPermission) .gqlPermission(defaultGqlPermission); } // Codegen instance; both intra-module FKs are always injected directly export const assignment = createAssignmentType();