Skip to content

Commit

Permalink
384 should solution and organization extend metarequirement (#405)
Browse files Browse the repository at this point in the history
* - Organizations and Solutions are now requirements
- generalized code

* - styling: datatables now have striped rows
- refactor: renamed enpoints to align with ReqType enum
- refactor: parent component properties moved to Belongs relations

* Lifted domain folder out of server folder

* Updated nuxt config settings
  • Loading branch information
mlhaufe authored Oct 23, 2024
1 parent 48eb81b commit ff40f5d
Show file tree
Hide file tree
Showing 287 changed files with 3,033 additions and 3,495 deletions.
109 changes: 0 additions & 109 deletions components/WorkboxDataView.vue

This file was deleted.

4 changes: 2 additions & 2 deletions components/XDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type Dialog from 'primevue/dialog'
import type DataTable from 'primevue/datatable'
import { FilterMatchMode } from 'primevue/api';
import camelCaseToTitle from '~/utils/camelCaseToTitle.js';
import { AuditLog } from '~/server/domain';
import { AuditLog } from '~/domain/application/index.js';
export type ViewFieldType = 'text' | 'textarea' | 'number' | 'date' | 'boolean' | 'hidden' | 'object'
Expand Down Expand Up @@ -183,7 +183,7 @@ const onEditDialogCancel = () => {
</Toolbar>
<DataTable ref="dataTable" :value="props.datasource as unknown as any[]" dataKey="id" v-model:filters="filters"
:globalFilterFields="Object.keys(props.datasource?.[0] ?? {})" :sortField="sortField" :sortOrder="1"
:loading="props.loading">
:loading="props.loading" stripedRows>
<Column
v-for="key of Object.keys(props.viewModel).filter(k => props.viewModel[k as keyof RowType] !== 'hidden')"
:key="key" :field="key" :header="camelCaseToTitle(key)" sortable>
Expand Down
File renamed without changes.
22 changes: 12 additions & 10 deletions server/domain/AppUser.ts → domain/application/AppUser.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { Entity, Enum, Property } from "@mikro-orm/core";
import { BaseEntity, Entity, Enum, Property } from "@mikro-orm/core";
import { AppRole } from "./AppRole.js";
import { type Properties } from "../types/index.js";

/**
* An AppUser is a user of the application
*/
@Entity()
export class AppUser {
constructor(properties: AppUser) {
this.id = properties.id;
this.creationDate = properties.creationDate;
this.isSystemAdmin = properties.isSystemAdmin;
this.lastLoginDate = properties.lastLoginDate;
this.name = properties.name;
this.email = properties.email;
this.role = properties.role;
export class AppUser extends BaseEntity {
constructor(props: Properties<AppUser>) {
super()
this.id = props.id;
this.creationDate = props.creationDate;
this.isSystemAdmin = props.isSystemAdmin;
this.lastLoginDate = props.lastLoginDate;
this.name = props.name;
this.email = props.email;
this.role = props.role;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Entity, Enum, ManyToOne } from "@mikro-orm/core";
import { BaseEntity, Entity, Enum, ManyToOne } from "@mikro-orm/core";
import { AppRole } from "./AppRole.js";
import { AppUser } from "./AppUser.js";
import { Organization } from "./Organization.js";
import { type Properties } from "../types/index.js";
import { Organization } from "../requirements/Organization.js";

/**
* An AppUserOrganizationRole is a mapping between an AppUser, an Organization, and a Role
*/
@Entity()
export class AppUserOrganizationRole {
constructor({ appUser, organization, role }: AppUserOrganizationRole) {
this.appUser = appUser;
this.organization = organization;
this.role = role;
export class AppUserOrganizationRole extends BaseEntity {
constructor(props: Properties<AppUserOrganizationRole>) {
super()
this.appUser = props.appUser;
this.organization = props.organization;
this.role = props.role;
}

/**
Expand All @@ -30,5 +32,5 @@ export class AppUserOrganizationRole {
* The Role associated with the OrganizationRole
*/
@Enum({ items: () => AppRole, primary: true })
role: AppRole = AppRole.ORGANIZATION_READER;
role: AppRole
}
14 changes: 9 additions & 5 deletions server/domain/AuditLog.ts → domain/application/AuditLog.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { v7 as uuidv7 } from 'uuid';
import { ChangeSetType, Entity, Enum, Property } from "@mikro-orm/core";
import { BaseEntity, ChangeSetType, Entity, Enum, Property } from "@mikro-orm/core";
import { type Properties } from '../types/index.js';

/**
* The AuditLog class is responsible for tracking changes to entities in the database.
*/
@Entity()
export class AuditLog {
constructor(props: Omit<AuditLog, 'id' | 'createdAt'>) {
export class AuditLog extends BaseEntity {
constructor(props: Properties<Omit<AuditLog, 'id' | 'createdAt'>> & { id?: string, createdAt?: Date }) {
super()
this.type = props.type;
this.entity = props.entity;
this.entityId = props.entityId;
this.entityName = props.entityName;
this.createdAt = props.createdAt || new Date();
this.id = props.id || uuidv7();
}

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

/**
* The unique identifier of the entity that was changed
Expand Down Expand Up @@ -47,5 +51,5 @@ export class AuditLog {
* The date and time when the AuditLog was created
*/
@Property({ type: 'datetime' })
createdAt: Date = new Date();
createdAt: Date
}
4 changes: 4 additions & 0 deletions domain/application/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './AppRole.js';
export * from './AppUser.js';
export * from './AppUserOrganizationRole.js';
export * from './AuditLog.js';
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X ⊆ Y
* X is a sub-requirement of Y
* X is textually included in Y
*
* X is a sub-requirement of Y; textually included
*/
@Entity()
export class Belongs extends RequirementRelation { }
17 changes: 17 additions & 0 deletions domain/relations/Characterizes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Entity } from "@mikro-orm/core";
import { RequirementRelation } from "./RequirementRelation.js";
import { MetaRequirement } from "../requirements/MetaRequirement.js";
import { type Properties } from "../types/index.js";

/**
* X → Y
*
* Meta-requirement X applies to requirement Y
*/
@Entity()
export class Characterizes extends RequirementRelation {
constructor(props: Properties<Omit<Characterizes, 'id' | 'left'> & { left: MetaRequirement }>) {
super(props);
this.left = props.left;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X ▸ Y
*
* Constraint X applies to Y
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X ⊕ Y
* X contradicts Y
*
* Properties specified by X and Y cannot both hold
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Extends } from "./Extends.js";

/**
* X » Y
*
* X adds detail to properties of Y
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X || Y
*
* X and Y are unrelated
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Repeats } from "./Repeats.js";
/**
* X ≡ Y
*
* X ⇔ Y, and X has the same type as Y
* In other words, X and Y are redundant
* X ⇔ Y, and X has the same type as Y.
* In other words, X and Y are redundant.
* Same properties, same type (notation-wise, X ≡ Y)
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X \\ Y
*
* X specifies an exception to the property specified by Y.
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Repeats } from "./Repeats.js";
* X ≅ Y
*
* X ⇔ Y, and X has a different type from Y.
*
* In other words, Y introduces no new property but helps understand X better.
*
* Same properties, different type (notation-wise)
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X > Y
* aka "refines"
* X assumes Y and specifies a property that Y does not
*
* aka "refines".
* X assumes Y and specifies a property that Y does not.
* X adds to properties of Y
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X ⊣ Y
*
* X is a consequence of the property specified by Y
*/
@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RequirementRelation } from "./RequirementRelation.js";

/**
* X ⇔ Y
*
* X specifies the same property as Y
*/
@Entity()
Expand Down
29 changes: 29 additions & 0 deletions domain/relations/RequirementRelation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { v7 as uuidv7 } from 'uuid';
import { BaseEntity, Cascade, Entity, ManyToOne, Property } 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'>>) {
super()
this.id = uuidv7();
this.left = props.left;
this.right = props.right;
}

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

@ManyToOne({ entity: () => Requirement, cascade: [Cascade.REMOVE] })
left: Requirement

@ManyToOne({ entity: () => Requirement, cascade: [Cascade.REMOVE] })
right: Requirement
}
Loading

0 comments on commit ff40f5d

Please sign in to comment.