diff --git a/packages/server/src/models/territory/territory.ts b/packages/server/src/models/territory/territory.ts index 1ac50e1d6..a80d2d90e 100644 --- a/packages/server/src/models/territory/territory.ts +++ b/packages/server/src/models/territory/territory.ts @@ -12,6 +12,10 @@ import User from "@models/user/user"; import treeCache from "@service/treeCache"; import { nonenumerable } from "@common/decorators"; import { ROOT_TERRITORY_ID } from "@shared/types/statement"; +import { + EProtocolTieType, + ITerritoryValidation, +} from "@shared/types/territory"; export class TerritoryParent implements IParentTerritory, IModel { territoryId: string; @@ -33,11 +37,17 @@ export class TerritoryParent implements IParentTerritory, IModel { export class TerritoryData implements ITerritoryData, IModel { parent: TerritoryParent | false = false; + validations?: TerritoryValidation[]; constructor(data: Partial) { if (data.parent) { this.parent = new TerritoryParent(data.parent || {}); } + if (data.validations) { + this.validations = data.validations.map( + (p) => new TerritoryValidation(p) + ); + } } isValid(): boolean { @@ -45,6 +55,42 @@ export class TerritoryData implements ITerritoryData, IModel { return this.parent.isValid(); } + if (this.validations) { + if (this.validations.find((p) => !p.isValid())) { + return false; + } + } + + return true; + } +} + +export class TerritoryValidation implements ITerritoryValidation { + entityClasses: EntityEnums.Class[]; + classifications: string[]; + tieType: EProtocolTieType; // default is property + tieLevel?: { + // relevant only in case of Classification or Property is selected as a tie + levelStatement: boolean; // default is true + levelMeta: boolean; // default is true + }; + propType?: string[]; // relevant only in case of Property is selected as a tie + allowedClasses?: EntityEnums.Class[]; // not relevant if allowedEntities is set + allowedEntities?: string[]; // + detail: string; + + constructor(data: Partial) { + this.entityClasses = data.entityClasses || []; + this.classifications = data.classifications || []; + this.tieType = data.tieType || EProtocolTieType.Property; + + this.propType = data.propType; + this.allowedClasses = data.allowedClasses; + this.allowedEntities = data.allowedEntities; + this.detail = data.detail || ""; + } + + isValid(): boolean { return true; } } diff --git a/packages/shared/types/territory.ts b/packages/shared/types/territory.ts index f2cba472c..f5243075a 100644 --- a/packages/shared/types/territory.ts +++ b/packages/shared/types/territory.ts @@ -1,5 +1,5 @@ -import { IEntity } from "./entity"; import { EntityEnums } from "../enums"; +import { IEntity } from "./entity"; export interface ITerritory extends IEntity { class: EntityEnums.Class.Territory; @@ -7,10 +7,32 @@ export interface ITerritory extends IEntity { } export interface ITerritoryData { - parent: IParentTerritory | false; + parent: IParentTerritory | false; // TODO should be optional instead of false + validations?: ITerritoryValidation[]; } export interface IParentTerritory { - territoryId: string; // '' in case of root + territoryId: string; order: number; } + +export interface ITerritoryValidation { + entityClasses: EntityEnums.Class[]; + classifications: string[]; + tieType: EProtocolTieType; // default is property + tieLevel?: { + // relevant only in case of Classification or Property is selected as a tie + levelStatement: boolean; // default is true + levelMeta: boolean; // default is true + }; + propType?: string[]; // relevant only in case of Property is selected as a tie + allowedClasses?: EntityEnums.Class[]; // not relevant if allowedEntities is set + allowedEntities?: string[]; // + detail: string; +} + +export enum EProtocolTieType { + Property = "Property", + Classification = "Classification", + Reference = "Reference", +}