Skip to content

Commit

Permalink
1985 protocols extend t model (#1993)
Browse files Browse the repository at this point in the history
* Add protocols to territory model

* Add more details to T protocol interface

* add TerritoryProtocol implementation

* protocol -> validation

* Remove Tie level

---------

Co-authored-by: adammertel <[email protected]>
  • Loading branch information
jancimertel and adammertel authored Mar 26, 2024
1 parent d133146 commit ab66970
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
46 changes: 46 additions & 0 deletions packages/server/src/models/territory/territory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,18 +37,60 @@ export class TerritoryParent implements IParentTerritory, IModel {

export class TerritoryData implements ITerritoryData, IModel {
parent: TerritoryParent | false = false;
validations?: TerritoryValidation[];

constructor(data: Partial<ITerritoryData>) {
if (data.parent) {
this.parent = new TerritoryParent(data.parent || {});
}
if (data.validations) {
this.validations = data.validations.map(
(p) => new TerritoryValidation(p)
);
}
}

isValid(): boolean {
if (this.parent) {
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<ITerritoryValidation>) {
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;
}
}
Expand Down
28 changes: 25 additions & 3 deletions packages/shared/types/territory.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import { IEntity } from "./entity";
import { EntityEnums } from "../enums";
import { IEntity } from "./entity";

export interface ITerritory extends IEntity {
class: EntityEnums.Class.Territory;
data: ITerritoryData;
}

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",
}

0 comments on commit ab66970

Please sign in to comment.