Skip to content

Commit

Permalink
463 add relationships to the requirement class directly (#468)
Browse files Browse the repository at this point in the history
* Initial refactoring.

* Updated Interactor

* Fixed CRUD operations with relations
  • Loading branch information
mlhaufe authored Nov 29, 2024
1 parent 3ef4636 commit 6a7dd34
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 256 deletions.
264 changes: 113 additions & 151 deletions application/OrganizationInteractor.ts

Large diffs are not rendered by default.

21 changes: 6 additions & 15 deletions domain/relations/RequirementRelation.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
import { v7 as uuidv7 } from 'uuid';
import { BaseEntity, Cascade, Entity, ManyToOne, Property } from "@mikro-orm/core";
import { BaseEntity, Entity, ManyToOne } from "@mikro-orm/core";
import { Requirement } from '../requirements/Requirement.js'
import { type Properties } from '../types/index.js';

/**
* Relations between requirements
*/
@Entity({ abstract: true, discriminatorColumn: 'rel_type' })
export abstract class RequirementRelation extends BaseEntity {
constructor(props: Properties<Omit<RequirementRelation, 'id'>>) {
constructor({ left, right }: { left: Requirement, right: Requirement }) {
super()
this.id = uuidv7();
this.left = props.left;
this.right = props.right;
this.left = left;
this.right = right;
}

/**
* The unique identifier of the RequirementRelation
*/
@Property({ type: 'uuid', primary: true })
id: string;

/**
* The left-hand side of the relation
*/
@ManyToOne({ entity: () => Requirement, cascade: [Cascade.REMOVE] })
@ManyToOne({ primary: true, entity: () => Requirement })
left: Requirement

/**
* The right-hand side of the relation
*/
@ManyToOne({ entity: () => Requirement, cascade: [Cascade.REMOVE] })
@ManyToOne({ primary: true, entity: () => Requirement })
right: Requirement
}
6 changes: 3 additions & 3 deletions domain/requirements/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReqType } from "./ReqType.js";
/**
* A part of a Project, Environment, System, or Goals that may affect or be affected by the associated entities
*/
@Entity({ abstract: true, discriminatorValue: ReqType.ACTOR })
export abstract class Actor extends Requirement {
@Entity({ discriminatorValue: ReqType.ACTOR })
export class Actor extends Requirement {
static override req_type: ReqType = ReqType.ACTOR;
}
}
5 changes: 2 additions & 3 deletions domain/requirements/Behavior.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Entity, Enum } from "@mikro-orm/core";
import { Requirement } from "./Requirement.js";
import { MoscowPriority } from "./MoscowPriority.js";
import { type Properties } from "../types/index.js";
import { ReqType } from "./ReqType.js";

/**
* Property of the operation of the system
*/
@Entity({ abstract: true, discriminatorValue: ReqType.BEHAVIOR })
@Entity({ discriminatorValue: ReqType.BEHAVIOR })
export class Behavior extends Requirement {
static override req_type: ReqType = ReqType.BEHAVIOR;

constructor({ priority, ...rest }: Properties<Omit<Behavior, 'id' | 'req_type'>>) {
constructor({ priority, ...rest }: ConstructorParameters<typeof Requirement>[0] & Pick<Behavior, 'priority'>) {
super(rest);
this.priority = priority;
}
Expand Down
4 changes: 2 additions & 2 deletions domain/requirements/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReqType } from "./ReqType.js";
/**
* Idenfitication of a part (of the Project, Environment, Goals, or System)
*/
@Entity({ abstract: true, discriminatorValue: ReqType.COMPONENT })
export abstract class Component extends Actor {
@Entity({ discriminatorValue: ReqType.COMPONENT })
export class Component extends Actor {
static override req_type: ReqType = ReqType.COMPONENT;
}
3 changes: 1 addition & 2 deletions domain/requirements/Constraint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Entity, Enum } from '@mikro-orm/core';
import { Requirement } from './Requirement.js';
import { ConstraintCategory } from './ConstraintCategory.js';
import { type Properties } from '../types/index.js';
import { ReqType } from './ReqType.js';

/**
Expand All @@ -12,7 +11,7 @@ export class Constraint extends Requirement {
static override reqIdPrefix = 'E.3.' as const;
static override req_type = ReqType.CONSTRAINT;

constructor({ category, ...rest }: Properties<Omit<Constraint, 'id' | 'req_type'>>) {
constructor({ category, ...rest }: ConstructorParameters<typeof Requirement>[0] & Pick<Constraint, 'category'>) {
super(rest);
this.category = category;
}
Expand Down
3 changes: 1 addition & 2 deletions domain/requirements/Epic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Entity, ManyToOne } from "@mikro-orm/core";
import { Scenario } from "./Scenario.js";
import { ReqType } from "./ReqType.js";
import type { Properties } from "../types/index.js";
import { FunctionalBehavior } from "./FunctionalBehavior.js";

/**
Expand All @@ -13,7 +12,7 @@ export class Epic extends Scenario {
static override reqIdPrefix = 'G.5.' as const;
static override req_type = ReqType.EPIC;

constructor(props: Properties<Omit<Epic, 'id' | 'req_type'>>) {
constructor(props: ConstructorParameters<typeof Scenario>[0] & Pick<Epic, 'functionalBehavior'>) {
super(props);
this.functionalBehavior = props.functionalBehavior;
}
Expand Down
6 changes: 3 additions & 3 deletions domain/requirements/Example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReqType } from "./ReqType.js";
/**
* Illustration of behavior through a usage scenario
*/
@Entity({ abstract: true, discriminatorValue: ReqType.EXAMPLE })
export abstract class Example extends Behavior {
@Entity({ discriminatorValue: ReqType.EXAMPLE })
export class Example extends Behavior {
static override req_type: ReqType = ReqType.EXAMPLE;
}
}
4 changes: 2 additions & 2 deletions domain/requirements/Functionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReqType } from "./ReqType.js";
/**
* Functionality describes what system will do and how it will do it.
*/
@Entity({ abstract: true, discriminatorValue: ReqType.FUNCTIONALITY })
export abstract class Functionality extends Behavior {
@Entity({ discriminatorValue: ReqType.FUNCTIONALITY })
export class Functionality extends Behavior {
static override req_type: ReqType = ReqType.FUNCTIONALITY;
}
4 changes: 2 additions & 2 deletions domain/requirements/Goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ReqType } from "./ReqType.js";
* an objective of the project or system, in terms
* of their desired effect on the environment
*/
@Entity({ abstract: true, discriminatorValue: ReqType.GOAL })
export abstract class Goal extends Requirement {
@Entity({ discriminatorValue: ReqType.GOAL })
export class Goal extends Requirement {
static override req_type: ReqType = ReqType.GOAL;
}
3 changes: 1 addition & 2 deletions domain/requirements/Invariant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Entity } from "@mikro-orm/core";
import { Requirement } from "./Requirement.js";
import { type Properties } from "../types/index.js";
import { ReqType } from "./ReqType.js";

/**
Expand All @@ -13,7 +12,7 @@ export class Invariant extends Requirement {
static override reqIdPrefix = 'E.6.' as const;
static override req_type: ReqType = ReqType.INVARIANT;

constructor(props: Properties<Omit<Invariant, 'id' | 'req_type'>>) {
constructor(props: ConstructorParameters<typeof Requirement>[0]) {
super(props);
this.req_type = ReqType.INVARIANT;
}
Expand Down
3 changes: 1 addition & 2 deletions domain/requirements/Organization.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Entity, Property } from "@mikro-orm/core";
import { slugify } from "../../shared/utils/slugify.js";
import { Requirement } from "./Requirement.js";
import { type Properties } from "../types/index.js";
import { ReqType } from "./ReqType.js";

/**
Expand All @@ -11,7 +10,7 @@ import { ReqType } from "./ReqType.js";
export class Organization extends Requirement {
static override req_type: ReqType = ReqType.ORGANIZATION

constructor(props: Properties<Omit<Organization, 'id' | 'slug' | 'req_type'>>) {
constructor(props: ConstructorParameters<typeof Requirement>[0]) {
super(props)
this._slug = slugify(props.name);
}
Expand Down
3 changes: 1 addition & 2 deletions domain/requirements/Person.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Entity, Property } from "@mikro-orm/core";
import { Actor } from "./Actor.js";
import { type Properties } from "../types/index.js";
import { ReqType } from "./ReqType.js";

/**
Expand All @@ -11,7 +10,7 @@ export class Person extends Actor {
static override req_type: ReqType = ReqType.PERSON;
static override reqIdPrefix = 'P.1.' as const;

constructor({ email, ...rest }: Properties<Omit<Person, 'id' | 'req_type'>>) {
constructor({ email, ...rest }: ConstructorParameters<typeof Actor>[0] & Pick<Person, 'email'>) {
super(rest);
this.email = email;
}
Expand Down
Loading

0 comments on commit 6a7dd34

Please sign in to comment.