diff --git a/src/database/migrations/20230911012943_make_default_value_on_recruited/migration.sql b/src/database/migrations/20230911012943_make_default_value_on_recruited/migration.sql new file mode 100644 index 0000000..0d2a3c7 --- /dev/null +++ b/src/database/migrations/20230911012943_make_default_value_on_recruited/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Study" ALTER COLUMN "recruited" SET DEFAULT 1; diff --git a/src/database/schema.prisma b/src/database/schema.prisma index d1967dd..5facac2 100644 --- a/src/database/schema.prisma +++ b/src/database/schema.prisma @@ -20,7 +20,7 @@ model Study { recruitStartDate DateTime startDate DateTime name String - recruited Int + recruited Int @default(1) locationDetail String templateContent String total Int diff --git a/src/study/study.controller.ts b/src/study/study.controller.ts index 252d957..6174e21 100644 --- a/src/study/study.controller.ts +++ b/src/study/study.controller.ts @@ -50,6 +50,11 @@ export class StudyController { return this.studyService.findNotices(+id); } + @Get(':id/notice') + findNotice(@Param('id') id: string): Promise { + return this.studyService.findNotice(+id); + } + @Get(':id/journals') findJournals(@Param('id') id: string): Promise { return this.studyService.findJournals(+id); diff --git a/src/study/study.service.ts b/src/study/study.service.ts index 011d808..b167399 100644 --- a/src/study/study.service.ts +++ b/src/study/study.service.ts @@ -196,6 +196,18 @@ export class StudyService { return notices.map((notice) => GetNoticeResponseDto.fromNotice(notice)); } + async findNotice(id: number): Promise { + const study = await this.findOne(id); + const notice = await this.prisma.notice.findFirst({ + where: { studyId: study.id }, + orderBy: { + updatedAt: 'desc', + }, + }); + + return GetNoticeResponseDto.fromNotice(notice); + } + async findJournals(id: number): Promise { const study = await this.findOne(id); const journals = await this.prisma.journal.findMany({