Skip to content

Commit 8a6746d

Browse files
committed
feat: questionnaire management
1 parent 5a3dc47 commit 8a6746d

File tree

11 files changed

+369
-43
lines changed

11 files changed

+369
-43
lines changed

.changeset/seven-mirrors-enjoy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@quassel/frontend": patch
3+
"@quassel/backend": patch
4+
---
5+
6+
Add questionnaire management

apps/backend/db/migrations/.snapshot-postgres.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
"unsigned": false,
284284
"autoincrement": false,
285285
"primary": false,
286-
"nullable": false,
286+
"nullable": true,
287287
"length": 6,
288288
"mappedType": "datetime"
289289
},
@@ -293,7 +293,7 @@
293293
"unsigned": false,
294294
"autoincrement": false,
295295
"primary": false,
296-
"nullable": false,
296+
"nullable": true,
297297
"length": 6,
298298
"mappedType": "datetime"
299299
},
@@ -303,7 +303,7 @@
303303
"unsigned": false,
304304
"autoincrement": false,
305305
"primary": false,
306-
"nullable": false,
306+
"nullable": true,
307307
"length": 255,
308308
"mappedType": "string"
309309
},
@@ -322,7 +322,7 @@
322322
"unsigned": false,
323323
"autoincrement": false,
324324
"primary": false,
325-
"nullable": false,
325+
"nullable": true,
326326
"mappedType": "integer"
327327
},
328328
"participant_id": {
@@ -331,7 +331,7 @@
331331
"unsigned": false,
332332
"autoincrement": false,
333333
"primary": false,
334-
"nullable": false,
334+
"nullable": true,
335335
"mappedType": "bigint"
336336
}
337337
},
@@ -361,6 +361,7 @@
361361
"id"
362362
],
363363
"referencedTableName": "public.study",
364+
"deleteRule": "set null",
364365
"updateRule": "cascade"
365366
},
366367
"questionnaire_participant_id_foreign": {
@@ -373,6 +374,7 @@
373374
"id"
374375
],
375376
"referencedTableName": "public.participant",
377+
"deleteRule": "set null",
376378
"updateRule": "cascade"
377379
}
378380
},
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Migration } from "@mikro-orm/migrations";
2+
3+
export class Migration20241108015549 extends Migration {
4+
override async up(): Promise<void> {
5+
this.addSql(`alter table "questionnaire" drop constraint "questionnaire_study_id_foreign";`);
6+
this.addSql(`alter table "questionnaire" drop constraint "questionnaire_participant_id_foreign";`);
7+
8+
this.addSql(`alter table "questionnaire" alter column "started_at" type timestamptz using ("started_at"::timestamptz);`);
9+
this.addSql(`alter table "questionnaire" alter column "started_at" drop not null;`);
10+
this.addSql(`alter table "questionnaire" alter column "ended_at" type timestamptz using ("ended_at"::timestamptz);`);
11+
this.addSql(`alter table "questionnaire" alter column "ended_at" drop not null;`);
12+
this.addSql(`alter table "questionnaire" alter column "title" type varchar(255) using ("title"::varchar(255));`);
13+
this.addSql(`alter table "questionnaire" alter column "title" drop not null;`);
14+
this.addSql(`alter table "questionnaire" alter column "study_id" type int using ("study_id"::int);`);
15+
this.addSql(`alter table "questionnaire" alter column "study_id" drop not null;`);
16+
this.addSql(`alter table "questionnaire" alter column "participant_id" type bigint using ("participant_id"::bigint);`);
17+
this.addSql(`alter table "questionnaire" alter column "participant_id" drop not null;`);
18+
this.addSql(
19+
`alter table "questionnaire" add constraint "questionnaire_study_id_foreign" foreign key ("study_id") references "study" ("id") on update cascade on delete set null;`
20+
);
21+
this.addSql(
22+
`alter table "questionnaire" add constraint "questionnaire_participant_id_foreign" foreign key ("participant_id") references "participant" ("id") on update cascade on delete set null;`
23+
);
24+
}
25+
26+
override async down(): Promise<void> {
27+
this.addSql(`alter table "questionnaire" drop constraint "questionnaire_study_id_foreign";`);
28+
this.addSql(`alter table "questionnaire" drop constraint "questionnaire_participant_id_foreign";`);
29+
30+
this.addSql(`alter table "questionnaire" alter column "started_at" type timestamptz using ("started_at"::timestamptz);`);
31+
this.addSql(`alter table "questionnaire" alter column "started_at" set not null;`);
32+
this.addSql(`alter table "questionnaire" alter column "ended_at" type timestamptz using ("ended_at"::timestamptz);`);
33+
this.addSql(`alter table "questionnaire" alter column "ended_at" set not null;`);
34+
this.addSql(`alter table "questionnaire" alter column "title" type varchar(255) using ("title"::varchar(255));`);
35+
this.addSql(`alter table "questionnaire" alter column "title" set not null;`);
36+
this.addSql(`alter table "questionnaire" alter column "study_id" type int using ("study_id"::int);`);
37+
this.addSql(`alter table "questionnaire" alter column "study_id" set not null;`);
38+
this.addSql(`alter table "questionnaire" alter column "participant_id" type bigint using ("participant_id"::bigint);`);
39+
this.addSql(`alter table "questionnaire" alter column "participant_id" set not null;`);
40+
this.addSql(
41+
`alter table "questionnaire" add constraint "questionnaire_study_id_foreign" foreign key ("study_id") references "study" ("id") on update cascade;`
42+
);
43+
this.addSql(
44+
`alter table "questionnaire" add constraint "questionnaire_participant_id_foreign" foreign key ("participant_id") references "participant" ("id") on update cascade;`
45+
);
46+
}
47+
}

apps/backend/src/research/questionnaires/questionnaire.dto.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ export class QuestionnaireDto {
1010

1111
@ApiProperty({ example: "2024-11-01T07:00:00.000Z", description: "The starting date of the questionnaire" })
1212
@IsDate()
13-
startedAt: Date;
13+
startedAt?: Date;
1414

1515
@ApiProperty({ example: "2024-11-01T08:00:00.00Z", description: "The ending date of the questionnaire" })
1616
@IsDate()
17-
endedAt: Date;
17+
endedAt?: Date;
1818

1919
@ApiProperty({ example: "First few months", description: "The title of the questionnaire" })
2020
@IsNotEmpty()
21-
title: string;
21+
title?: string;
2222

2323
@ApiProperty({ example: "We went on holidays for 2 weeks and only spoke Esperanto", description: "The remark of the questionnaire" })
2424
remark?: string;
2525

2626
@Type(() => StudyDto)
27-
study: StudyDto;
27+
study?: StudyDto;
2828

2929
@Type(() => ParticipantDto)
30-
participant: ParticipantDto;
30+
participant?: ParticipantDto;
3131

3232
@Type(() => Array<number>)
33-
entries: number[];
33+
entries?: number[];
3434
}
3535
export class QuestionnaireResponseDto extends QuestionnaireDto {}
3636
export class QuestionnaireCreationDto extends OmitType(QuestionnaireDto, ["id"]) {}

apps/backend/src/research/questionnaires/questionnaire.entity.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import { Entry } from "../entries/entry.entity";
77
@Entity()
88
export class Questionnaire extends BaseEntity {
99
@Property()
10-
startedAt!: Date;
10+
startedAt?: Date;
1111

1212
@Property()
13-
endedAt!: Date;
13+
endedAt?: Date;
1414

1515
@Property()
16-
title!: string;
16+
title?: string;
1717

1818
@Property({ columnType: "text" })
1919
remark?: string;
2020

2121
@ManyToOne()
22-
study!: Study;
22+
study?: Study;
2323

2424
@ManyToOne()
25-
participant!: Participant;
25+
participant?: Participant;
2626

2727
@OneToMany(() => Entry, (entry) => entry.questionnaire)
2828
entries = new Collection<Entry>(this);

apps/frontend/src/api.gen.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -612,26 +612,26 @@ export interface components {
612612
* @description The starting date of the questionnaire
613613
* @example 2024-11-01T07:00:00.000Z
614614
*/
615-
startedAt: string;
615+
startedAt?: string;
616616
/**
617617
* Format: date-time
618618
* @description The ending date of the questionnaire
619619
* @example 2024-11-01T08:00:00.00Z
620620
*/
621-
endedAt: string;
621+
endedAt?: string;
622622
/**
623623
* @description The title of the questionnaire
624624
* @example First few months
625625
*/
626-
title: string;
626+
title?: string;
627627
/**
628628
* @description The remark of the questionnaire
629629
* @example We went on holidays for 2 weeks and only spoke Esperanto
630630
*/
631631
remark?: string;
632-
study: components["schemas"]["StudyDto"];
633-
participant: components["schemas"]["ParticipantDto"];
634-
entries: number[];
632+
study?: components["schemas"]["StudyDto"];
633+
participant?: components["schemas"]["ParticipantDto"];
634+
entries?: number[];
635635
};
636636
CarerDto: {
637637
/**
@@ -733,26 +733,26 @@ export interface components {
733733
* @description The starting date of the questionnaire
734734
* @example 2024-11-01T07:00:00.000Z
735735
*/
736-
startedAt: string;
736+
startedAt?: string;
737737
/**
738738
* Format: date-time
739739
* @description The ending date of the questionnaire
740740
* @example 2024-11-01T08:00:00.00Z
741741
*/
742-
endedAt: string;
742+
endedAt?: string;
743743
/**
744744
* @description The title of the questionnaire
745745
* @example First few months
746746
*/
747-
title: string;
747+
title?: string;
748748
/**
749749
* @description The remark of the questionnaire
750750
* @example We went on holidays for 2 weeks and only spoke Esperanto
751751
*/
752752
remark?: string;
753-
study: components["schemas"]["StudyDto"];
754-
participant: components["schemas"]["ParticipantDto"];
755-
entries: number[];
753+
study?: components["schemas"]["StudyDto"];
754+
participant?: components["schemas"]["ParticipantDto"];
755+
entries?: number[];
756756
};
757757
QuestionnaireResponseDto: {
758758
/**
@@ -765,26 +765,26 @@ export interface components {
765765
* @description The starting date of the questionnaire
766766
* @example 2024-11-01T07:00:00.000Z
767767
*/
768-
startedAt: string;
768+
startedAt?: string;
769769
/**
770770
* Format: date-time
771771
* @description The ending date of the questionnaire
772772
* @example 2024-11-01T08:00:00.00Z
773773
*/
774-
endedAt: string;
774+
endedAt?: string;
775775
/**
776776
* @description The title of the questionnaire
777777
* @example First few months
778778
*/
779-
title: string;
779+
title?: string;
780780
/**
781781
* @description The remark of the questionnaire
782782
* @example We went on holidays for 2 weeks and only spoke Esperanto
783783
*/
784784
remark?: string;
785-
study: components["schemas"]["StudyDto"];
786-
participant: components["schemas"]["ParticipantDto"];
787-
entries: number[];
785+
study?: components["schemas"]["StudyDto"];
786+
participant?: components["schemas"]["ParticipantDto"];
787+
entries?: number[];
788788
};
789789
QuestionnaireMutationDto: {
790790
/**

0 commit comments

Comments
 (0)