Skip to content

Commit

Permalink
- optimized page middleware
Browse files Browse the repository at this point in the history
- bugfixed organization delete message
- bugfixed org landing page solution list after delete
- refactored domain to export from index file to avoid circular dependency errors
- Organization now explicitly references solutions
- Solution now explicitly references associated requirements
- Justifications now created w/ Solution instead of lazily on rationale page
  • Loading branch information
mlhaufe committed Aug 31, 2024
1 parent e26308f commit 7fcc1ae
Show file tree
Hide file tree
Showing 166 changed files with 462 additions and 335 deletions.
8 changes: 4 additions & 4 deletions middleware/org-solution-check.global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
*/
export default defineNuxtRouteMiddleware(async (to, from) => {
if (to.params.organizationslug) {
const { data: organizations } = await useFetch('/api/organizations', {
const organizations = await $fetch('/api/organizations', {
query: { slug: to.params.organizationslug }
})

if (!(organizations?.value ?? []).length) {
if (!(organizations ?? []).length) {
return navigateTo('/')
} else if (to.params.solutionslug) {
const { data: solutions } = await useFetch('/api/solutions', {
const solutions = await $fetch('/api/solutions', {
query: {
organizationSlug: to.params.organizationslug,
slug: to.params.solutionslug
}
})

if (!(solutions?.value ?? []).length)
if (!(solutions ?? []).length)
return navigateTo(`/o/${to.params.organizationslug}`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion migrations/.snapshot-cathedral.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
"id"
],
"referencedTableName": "public.organization",
"deleteRule": "cascade"
"updateRule": "cascade"
}
},
"nativeEnums": {}
Expand Down
17 changes: 17 additions & 0 deletions migrations/Migration20240831162504.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240831162504 extends Migration {

override async up(): Promise<void> {
this.addSql('alter table "solution" drop constraint "solution_organization_id_foreign";');

this.addSql('alter table "solution" add constraint "solution_organization_id_foreign" foreign key ("organization_id") references "organization" ("id") on update cascade;');
}

override async down(): Promise<void> {
this.addSql('alter table "solution" drop constraint "solution_organization_id_foreign";');

this.addSql('alter table "solution" add constraint "solution_organization_id_foreign" foreign key ("organization_id") references "organization" ("id") on delete cascade;');
}

}
19 changes: 8 additions & 11 deletions pages/index.client.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<script lang="ts" setup>
import Organization from '~/server/domain/application/Organization';
import type { Properties } from '~/server/domain/Properties';
definePageMeta({ name: 'Home' })
const router = useRouter(),
Expand All @@ -12,9 +9,9 @@ const router = useRouter(),
if (getOrgError.value)
$eventBus.$emit('page-error', getOrgError.value)
const handleDelete = async (organization: Properties<Organization>) => {
const handleDelete = async (organization: { id: string, name: string }) => {
confirm.require({
message: `Are you sure you want to delete ${Organization.name}? This will also delete all associated solutions.`,
message: `Are you sure you want to delete ${organization.name}? This will also delete all associated solutions.`,
header: 'Delete Confirmation',
icon: 'pi pi-exclamation-triangle',
rejectLabel: 'Cancel',
Expand All @@ -29,11 +26,11 @@ const handleDelete = async (organization: Properties<Organization>) => {
})
}
const handleEdit = (organization: Organization) => {
const handleEdit = (organization: { slug: string }) => {
router.push({ name: 'Edit Organization', params: { organizationslug: organization.slug } });
}
const handleUsers = (organization: Organization) => {
const handleUsers = (organization: { slug: string }) => {
router.push({ name: 'Organization Users', params: { organizationslug: organization.slug } });
}
</script>
Expand Down Expand Up @@ -64,12 +61,12 @@ const handleUsers = (organization: Organization) => {
{{ organization.description }}
</template>
<template #footer>
<Button icon="pi pi-pencil" class="edit-button mr-2" @click="handleEdit(organization as Organization)"
<Button icon="pi pi-pencil" class="edit-button mr-2" @click="handleEdit(organization)"
title="Edit Organization" />
<Button icon="pi pi-users" class="edit-button mr-2" @click="handleUsers(organization as Organization)"
<Button icon="pi pi-users" class="edit-button mr-2" @click="handleUsers(organization)"
title="Manage Users" />
<Button icon="pi pi-trash" class="delete-button" @click="handleDelete(organization as Organization)"
severity="danger" title="Delete Organization" />
<Button icon="pi pi-trash" class="delete-button" @click="handleDelete(organization)" severity="danger"
title="Delete Organization" />
</template>
</Card>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { useFetch } from 'nuxt/app';
import { FilterMatchMode } from 'primevue/api';
import ConstraintCategory from '~/server/domain/requirements/ConstraintCategory';
import { ConstraintCategory } from '~/server/domain/requirements/index';
import { NIL as emptyUuid } from 'uuid';
useHead({ title: 'Constraints' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { FilterMatchMode } from 'primevue/api';
import MoscowPriority from '~/server/domain/requirements/MoscowPriority';
import { MoscowPriority } from '~/server/domain/requirements/index';
import { NIL as emptyUuid } from 'uuid';
useHead({ title: 'Functionality' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type JustificationModel = {
}
const [
{ data: visionJustifications, refresh: refreshVision, error: getVisionError },
{ data: missionJustifications, refresh: refreshMission, error: getMissionError },
{ data: situationJustifications, refresh: refreshSituation, error: getSituationError },
{ data: objectiveJustifications, refresh: refreshObjective, error: getObjectiveError }
{ data: visionJustifications, error: getVisionError },
{ data: missionJustifications, error: getMissionError },
{ data: situationJustifications, error: getSituationError },
{ data: objectiveJustifications, error: getObjectiveError }
] = await Promise.all([
useFetch(`/api/justifications?solutionId=${solutionId}&name=Vision`),
useFetch(`/api/justifications?solutionId=${solutionId}&name=Mission`),
Expand All @@ -42,41 +42,6 @@ if (getSituationError.value)
if (getObjectiveError.value)
$eventBus.$emit('page-error', getObjectiveError.value);
if (!visionJustifications.value?.length) {
useFetch(`/api/justifications`, {
method: 'POST',
body: { solutionId, name: 'Vision', statement: '' }
}).catch((e) => $eventBus.$emit('page-error', e));
}
if (!missionJustifications.value?.length) {
useFetch(`/api/justifications`, {
method: 'POST',
body: { solutionId, name: 'Mission', statement: '' }
}).catch((e) => $eventBus.$emit('page-error', e));
}
if (!situationJustifications.value?.length) {
useFetch(`/api/justifications`, {
method: 'POST',
body: { solutionId, name: 'Situation', statement: '' }
}).catch((e) => $eventBus.$emit('page-error', e));
}
if (!objectiveJustifications.value?.length) {
useFetch(`/api/justifications`, {
method: 'POST',
body: { solutionId, name: 'Objective', statement: '' }
}).catch((e) => $eventBus.$emit('page-error', e));
}
await Promise.all([
refreshVision(),
refreshMission(),
refreshSituation(),
refreshObjective()
]);
const visionStatement = ref(visionJustifications.value?.[0].statement!),
missionStatement = ref(missionJustifications.value?.[0].statement!),
situationStatement = ref(situationJustifications.value?.[0].statement!),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { FilterMatchMode } from 'primevue/api';
import MoscowPriority from '~/server/domain/requirements/MoscowPriority';
import { MoscowPriority } from '~/server/domain/requirements/index';
import { NIL as emptyUuid } from 'uuid';
useHead({ title: 'Scenarios' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts" setup>
import { FilterMatchMode } from 'primevue/api';
import mermaid from 'mermaid';
import StakeholderCategory from '~/server/domain/requirements/StakeholderCategory';
import StakeholderSegmentation from '~/server/domain/requirements/StakeholderSegmentation';
import { StakeholderCategory, StakeholderSegmentation } from '~/server/domain/requirements/index';
import { NIL as emptyUuid } from 'uuid';
useHead({ title: 'Stakeholders' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { FilterMatchMode } from 'primevue/api';
import MoscowPriority from '~/server/domain/requirements/MoscowPriority';
import { MoscowPriority } from '~/server/domain/requirements/index';
import { NIL as emptyUuid } from 'uuid';
useHead({ title: 'Functionality' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { FilterMatchMode } from 'primevue/api';
import MoscowPriority from '~/server/domain/requirements/MoscowPriority';
import { MoscowPriority } from '~/server/domain/requirements/index';
import { NIL as emptyUuid } from 'uuid';
useHead({ title: 'Scenarios' })
Expand Down
4 changes: 2 additions & 2 deletions pages/o/[organization-slug]/index.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { $eventBus } = useNuxtApp(),
query: { slug: organizationslug }
}),
organization = organizations.value![0],
{ refresh, status, data: solutions, error: getSolutionError } = await useFetch('/api/solutions', {
{ refresh: refreshSolutions, status, data: solutions, error: getSolutionError } = await useFetch('/api/solutions', {
query: { organizationSlug: organizationslug }
}),
confirm = useConfirm()
Expand Down Expand Up @@ -65,7 +65,7 @@ const handleSolutionDelete = async (solution: Properties<SolutionModel>) => {
await $fetch(`/api/solutions/${solution.id}`, {
method: 'delete'
}).catch((e) => $eventBus.$emit('page-error', e))
router.push({ name: 'Organization', params: { organizationslug } });
await refreshSolutions()
},
reject: () => { }
})
Expand Down
2 changes: 1 addition & 1 deletion server/api/assumptions/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import Assumption from "~/server/domain/requirements/Assumption"
import { Assumption } from "~/server/domain/requirements/index"

/**
* Delete an assumption by id.
Expand Down
2 changes: 1 addition & 1 deletion server/api/assumptions/[id].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import Assumption from "~/server/domain/requirements/Assumption"
import { Assumption } from "~/server/domain/requirements/index"

/**
* Returns an assumption by id
Expand Down
2 changes: 1 addition & 1 deletion server/api/assumptions/[id].put.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fork } from "~/server/data/orm"
import { z } from "zod"
import Assumption from "~/server/domain/requirements/Assumption"
import { Assumption } from "~/server/domain/requirements/index"
import Solution from "~/server/domain/application/Solution"

const bodySchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion server/api/assumptions/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import Assumption from "~/server/domain/requirements/Assumption"
import { Assumption } from "~/server/domain/requirements/index"

const querySchema = z.object({
name: z.string().optional(),
Expand Down
2 changes: 1 addition & 1 deletion server/api/assumptions/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fork } from "~/server/data/orm"
import { z } from "zod"
import Assumption from "~/server/domain/requirements/Assumption"
import { Assumption } from "~/server/domain/requirements/index"
import Solution from "~/server/domain/application/Solution"

const bodySchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion server/api/constraints/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import Constraint from "~/server/domain/requirements/Constraint"
import { Constraint } from "~/server/domain/requirements/index"

/**
* Delete constraint by id.
Expand Down
2 changes: 1 addition & 1 deletion server/api/constraints/[id].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import Constraint from "~/server/domain/requirements/Constraint"
import { Constraint } from "~/server/domain/requirements/index"

/**
* Returns a constraint by id
Expand Down
3 changes: 1 addition & 2 deletions server/api/constraints/[id].put.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { z } from "zod"
import Constraint from "~/server/domain/requirements/Constraint"
import ConstraintCategory from "~/server/domain/requirements/ConstraintCategory"
import { Constraint, ConstraintCategory } from "~/server/domain/requirements/index"
import { fork } from "~/server/data/orm"
import Solution from "~/server/domain/application/Solution"

Expand Down
3 changes: 1 addition & 2 deletions server/api/constraints/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import Constraint from "~/server/domain/requirements/Constraint"
import ConstraintCategory from "~/server/domain/requirements/ConstraintCategory"
import { Constraint, ConstraintCategory } from "~/server/domain/requirements/index"

const querySchema = z.object({
name: z.string().optional(),
Expand Down
3 changes: 1 addition & 2 deletions server/api/constraints/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import Constraint from "~/server/domain/requirements/Constraint"
import { Constraint, ConstraintCategory } from "~/server/domain/requirements/index"
import Solution from "~/server/domain/application/Solution"
import ConstraintCategory from "~/server/domain/requirements/ConstraintCategory"

const bodySchema = z.object({
name: z.string().min(1),
Expand Down
2 changes: 1 addition & 1 deletion server/api/effects/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import Effect from "~/server/domain/requirements/Effect"
import { Effect } from "~/server/domain/requirements/index"

/**
* Delete an effect by id.
Expand Down
2 changes: 1 addition & 1 deletion server/api/effects/[id].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import Effect from "~/server/domain/requirements/Effect"
import { Effect } from "~/server/domain/requirements/index"

/**
* Returns an effect by id
Expand Down
2 changes: 1 addition & 1 deletion server/api/effects/[id].put.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fork } from "~/server/data/orm"
import { z } from "zod"
import Effect from "~/server/domain/requirements/Effect"
import { Effect } from "~/server/domain/requirements/index"
import Solution from "~/server/domain/application/Solution"

const bodySchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion server/api/effects/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import Effect from "~/server/domain/requirements/Effect"
import { Effect } from "~/server/domain/requirements/index"

const querySchema = z.object({
name: z.string().optional(),
Expand Down
2 changes: 1 addition & 1 deletion server/api/effects/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fork } from "~/server/data/orm"
import { z } from "zod"
import Effect from "~/server/domain/requirements/Effect"
import { Effect } from "~/server/domain/requirements/index"
import Solution from "~/server/domain/application/Solution"

const bodySchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion server/api/environment-components/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import EnvironmentComponent from "~/server/domain/requirements/EnvironmentComponent"
import { EnvironmentComponent } from "~/server/domain/requirements/index"

/**
* Delete an environment component by id.
Expand Down
2 changes: 1 addition & 1 deletion server/api/environment-components/[id].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import EnvironmentComponent from "~/server/domain/requirements/EnvironmentComponent"
import { EnvironmentComponent } from "~/server/domain/requirements/index"

/**
* Returns an environment component by id
Expand Down
2 changes: 1 addition & 1 deletion server/api/environment-components/[id].put.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import EnvironmentComponent from "~/server/domain/requirements/EnvironmentComponent"
import { EnvironmentComponent } from "~/server/domain/requirements/index"
import Solution from "~/server/domain/application/Solution"

const bodySchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion server/api/environment-components/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import EnvironmentComponent from "~/server/domain/requirements/EnvironmentComponent"
import { EnvironmentComponent } from "~/server/domain/requirements/index"

const querySchema = z.object({
name: z.string().optional(),
Expand Down
2 changes: 1 addition & 1 deletion server/api/environment-components/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod"
import { fork } from "~/server/data/orm"
import Solution from "~/server/domain/application/Solution"
import EnvironmentComponent from "~/server/domain/requirements/EnvironmentComponent"
import { EnvironmentComponent } from "~/server/domain/requirements/index"

const bodySchema = z.object({
name: z.string(),
Expand Down
2 changes: 1 addition & 1 deletion server/api/functional-behaviors/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import FunctionalBehavior from "~/server/domain/requirements/FunctionalBehavior"
import { FunctionalBehavior } from "~/server/domain/requirements/index"

/**
* Delete an functional behavior by id.
Expand Down
2 changes: 1 addition & 1 deletion server/api/functional-behaviors/[id].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fork } from "~/server/data/orm"
import FunctionalBehavior from "~/server/domain/requirements/FunctionalBehavior"
import { FunctionalBehavior } from "~/server/domain/requirements/index"

/**
* Returns a functional behavior by id
Expand Down
Loading

0 comments on commit 7fcc1ae

Please sign in to comment.