Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/seven-penguins-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@quassel/frontend": patch
"@quassel/backend": patch
---

Prevent user from deleting study which already is connected to any questionnaires
6 changes: 5 additions & 1 deletion apps/backend/src/research/studies/study.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class StudyBaseDto {
title: string;
}

export class StudyResponseDto extends StudyBaseDto {}
export class StudyResponseDto extends StudyBaseDto {
@ApiProperty({ example: 1, description: "The count of questionnaires tracked to this study" })
@Expose()
questionnairesCount?: number;
}
export class StudyCreationDto extends StudyBaseDto {}
export class StudyMutationDto extends PartialType(StudyBaseDto) {}
5 changes: 4 additions & 1 deletion apps/backend/src/research/studies/study.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Collection, Entity, OneToMany, Property } from "@mikro-orm/core";
import { Collection, Entity, Formula, OneToMany, Property } from "@mikro-orm/core";
import { BaseEntity } from "../../common/entities/base.entity";
import { Questionnaire } from "../questionnaires/questionnaire.entity";

Expand All @@ -9,4 +9,7 @@

@OneToMany(() => Questionnaire, (questionnaire) => questionnaire.study)
questionnaires = new Collection<Questionnaire>(this);

@Formula((alias) => `(select count(*) from questionnaire q where q.study_id = ${alias}.id)`)

Check warning on line 13 in apps/backend/src/research/studies/study.entity.ts

View check run for this annotation

Codecov / codecov/patch

apps/backend/src/research/studies/study.entity.ts#L13

Added line #L13 was not covered by tests
questionnairesCount? = 0;
}
13 changes: 9 additions & 4 deletions apps/frontend/src/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ export interface components {
* @example Series 1
*/
title: string;
/**
* @description The count of questionnaires tracked to this study
* @example 1
*/
questionnairesCount?: number;
};
QuestionnaireResponseDto: {
/**
Expand Down Expand Up @@ -1310,19 +1315,19 @@ export interface operations {
};
ReportsController_get: {
parameters: {
query?: {
studyId?: string;
query: {
studyId: string;
};
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Database dump file */
/** @description Report file */
200: {
headers: {
/** @description Attachment dump */
/** @description Report */
"Content-Disposition"?: string;
[name: string]: unknown;
};
Expand Down
30 changes: 16 additions & 14 deletions apps/frontend/src/routes/_auth/administration/studies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@
<Table.Td>{s.id}</Table.Td>
<Table.Td>{s.title}</Table.Td>
<Table.Td>
<Button variant="default" renderRoot={(props) => <Link to={`/administration/studies/edit/${s.id}`} {...props} />}>
Edit
</Button>
{sessionStore.role === "ADMIN" && (
<Button
variant="default"
onClick={() =>
deleteStudyMutation.mutate({
params: { path: { id: s.id.toString() } },
})
}
>
Delete
<Button.Group>
<Button variant="default" renderRoot={(props) => <Link to={`/administration/studies/edit/${s.id}`} {...props} />}>

Check warning on line 30 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
Edit
</Button>
)}
{sessionStore.role === "ADMIN" && (s.questionnairesCount ?? 0) < 1 && (
<Button
variant="default"
onClick={() =>
deleteStudyMutation.mutate({
params: { path: { id: s.id.toString() } },
})

Check warning on line 39 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L33-L39

Added lines #L33 - L39 were not covered by tests
}
>

Check warning on line 41 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L41

Added line #L41 was not covered by tests
Delete
</Button>

Check warning on line 43 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L43

Added line #L43 was not covered by tests
)}
</Button.Group>

Check warning on line 45 in apps/frontend/src/routes/_auth/administration/studies/index.tsx

View check run for this annotation

Codecov / codecov/patch

apps/frontend/src/routes/_auth/administration/studies/index.tsx#L45

Added line #L45 was not covered by tests
</Table.Td>
</Table.Tr>
))}
Expand Down