From 81c697d9dcfc3aa14ab497f5948e5153c3e49d5d Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 14:51:22 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=90=9B=20access=5Ftoken=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20refresh=20token=20httponly=3Dtrue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/auth/auth.controller.ts | 2 +- app/backend/src/auth/auth.service.ts | 2 +- app/backend/src/member/member.service.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/backend/src/auth/auth.controller.ts b/app/backend/src/auth/auth.controller.ts index 473a01a8c..38c1fe7f4 100644 --- a/app/backend/src/auth/auth.controller.ts +++ b/app/backend/src/auth/auth.controller.ts @@ -84,7 +84,7 @@ export class AuthController { res.cookie('access_token', tokens.access_token, { httpOnly: false, maxAge: getSecret('MAX_AGE_ACCESS_TOKEN') }); res.cookie('refresh_token', tokens.refresh_token, { - httpOnly: false, + httpOnly: true, maxAge: getSecret('MAX_AGE_REFRESH_TOKEN'), }); diff --git a/app/backend/src/auth/auth.service.ts b/app/backend/src/auth/auth.service.ts index 7812b9e05..3547b6b77 100644 --- a/app/backend/src/auth/auth.service.ts +++ b/app/backend/src/auth/auth.service.ts @@ -26,7 +26,7 @@ export class AuthService { generateJwt(payload: Payload): Tokens { const accessToken = this.jwtService.sign(payload, { expiresIn: getSecret('MAX_AGE_ACCESS_TOKEN'), - secret: getSecret('MAX_AGE_ACCESS_TOKEN'), + secret: getSecret('JWT_ACCESS_SECRET'), }); const refreshToken = this.jwtService.sign(payload, { diff --git a/app/backend/src/member/member.service.ts b/app/backend/src/member/member.service.ts index 43d156ee7..5f5e2b066 100644 --- a/app/backend/src/member/member.service.ts +++ b/app/backend/src/member/member.service.ts @@ -1,13 +1,14 @@ import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { MemberDto } from './dto/member.dto'; +import { getSecret } from 'vault'; @Injectable() export class MemberService { constructor(private jwtService: JwtService) {} async getUserData(encryptedToken: string): Promise { - const decodedAccessToken = this.jwtService.verify(encryptedToken, { secret: process.env.JWT_ACCESS_SECRET }); + const decodedAccessToken = this.jwtService.verify(encryptedToken, { secret: getSecret(`JWT_ACCESS_SECRET`) }); const { providerId, email, nickname, profilePicture } = decodedAccessToken; return { providerId, email, nickname, profilePicture }; From 57e592123641d98164ac3adc3f79d5b40b525434 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 15:26:18 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=E2=9C=A8=20=EB=AA=A8=EA=B0=81=EC=BD=94=20A?= =?UTF-8?q?PI=20Setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/app.module.ts | 2 ++ .../src/mogaco/dto/create-mogaco.dto.ts | 21 +++++++++++++++++++ .../src/mogaco/dto/mogaco-status.enum.ts | 5 +++++ app/backend/src/mogaco/mogaco.module.ts | 11 ++++++++++ 4 files changed, 39 insertions(+) create mode 100644 app/backend/src/mogaco/dto/create-mogaco.dto.ts create mode 100644 app/backend/src/mogaco/dto/mogaco-status.enum.ts create mode 100644 app/backend/src/mogaco/mogaco.module.ts diff --git a/app/backend/src/app.module.ts b/app/backend/src/app.module.ts index 76d1e2687..a069d665b 100644 --- a/app/backend/src/app.module.ts +++ b/app/backend/src/app.module.ts @@ -5,6 +5,7 @@ import { AppController } from './app.controller'; import { MemberModule } from './member/member.module'; import * as redisStore from 'cache-manager-redis-store'; import { getSecret } from 'vault'; +import { MogacoModule } from './mogaco/mogaco.module'; @Module({ imports: [ @@ -16,6 +17,7 @@ import { getSecret } from 'vault'; }), AuthModule, MemberModule, + MogacoModule, ], controllers: [AppController], providers: [], diff --git a/app/backend/src/mogaco/dto/create-mogaco.dto.ts b/app/backend/src/mogaco/dto/create-mogaco.dto.ts new file mode 100644 index 000000000..493e10c46 --- /dev/null +++ b/app/backend/src/mogaco/dto/create-mogaco.dto.ts @@ -0,0 +1,21 @@ +import { IsDateString, IsNotEmpty } from 'class-validator'; + +export class CreateMogacoDto { + @IsNotEmpty() + title: string; + + @IsNotEmpty() + contents: string; + + @IsNotEmpty() + @IsDateString() + date: string; + + @IsNotEmpty() + max_human_count: number; + + @IsNotEmpty() + address: string; + + status: string; +} diff --git a/app/backend/src/mogaco/dto/mogaco-status.enum.ts b/app/backend/src/mogaco/dto/mogaco-status.enum.ts new file mode 100644 index 000000000..a4ed387f7 --- /dev/null +++ b/app/backend/src/mogaco/dto/mogaco-status.enum.ts @@ -0,0 +1,5 @@ +export enum MogacoStatus { + RECRUITING = '모집 중', + CLOSED = '모집 마감', + COMPLETED = '종료', +} diff --git a/app/backend/src/mogaco/mogaco.module.ts b/app/backend/src/mogaco/mogaco.module.ts new file mode 100644 index 000000000..e940b8376 --- /dev/null +++ b/app/backend/src/mogaco/mogaco.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { MogacoService } from './mogaco.service'; +import { MogacoController } from './mogaco.controller'; +import { MogacoRepository } from './mogaco.repository'; +import { PrismaService } from 'libs/utils/prisma.service'; + +@Module({ + controllers: [MogacoController], + providers: [MogacoService, MogacoRepository, PrismaService], +}) +export class MogacoModule {} From 7f6773bf074230ed778e866a1431355e5282e909 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 15:26:43 +0900 Subject: [PATCH 3/8] =?UTF-8?q?=E2=9C=A8=20BigInt=20json=20=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/libs/utils/bigIntToJson.ts | 3 +++ app/backend/src/main.ts | 1 + 2 files changed, 4 insertions(+) create mode 100644 app/backend/libs/utils/bigIntToJson.ts diff --git a/app/backend/libs/utils/bigIntToJson.ts b/app/backend/libs/utils/bigIntToJson.ts new file mode 100644 index 000000000..db853b5a2 --- /dev/null +++ b/app/backend/libs/utils/bigIntToJson.ts @@ -0,0 +1,3 @@ +(BigInt.prototype as any).toJSON = function () { + return this.toString(); +}; diff --git a/app/backend/src/main.ts b/app/backend/src/main.ts index 75707ad60..3e9e7c8d7 100644 --- a/app/backend/src/main.ts +++ b/app/backend/src/main.ts @@ -4,6 +4,7 @@ import * as cookieParser from 'cookie-parser'; import { ValidationPipe } from '@nestjs/common'; import { setupSwagger } from '../libs/utils/swagger'; import { getSecret, loadSecrets } from 'vault'; +import '../libs/utils/bigIntToJson'; async function bootstrap() { await loadSecrets(); From 28c429cca33404628ff777bb79e23927f78253db Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 15:27:07 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=E2=9C=A8=20=EB=AA=A8=EA=B0=81=EC=BD=94=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EB=B0=8F=20=EC=83=81=EC=84=B8=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/mogaco/mogaco.controller.ts | 18 ++++++++++++++++++ app/backend/src/mogaco/mogaco.repository.ts | 18 ++++++++++++++++++ app/backend/src/mogaco/mogaco.service.ts | 16 ++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 app/backend/src/mogaco/mogaco.controller.ts create mode 100644 app/backend/src/mogaco/mogaco.repository.ts create mode 100644 app/backend/src/mogaco/mogaco.service.ts diff --git a/app/backend/src/mogaco/mogaco.controller.ts b/app/backend/src/mogaco/mogaco.controller.ts new file mode 100644 index 000000000..800b5c597 --- /dev/null +++ b/app/backend/src/mogaco/mogaco.controller.ts @@ -0,0 +1,18 @@ +import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common'; +import { MogacoService } from './mogaco.service'; +import { Mogaco } from '@prisma/client'; + +@Controller('mogaco') +export class MogacoController { + constructor(private readonly mogacoService: MogacoService) {} + + @Get('/') + async getAllMogaco(): Promise { + return this.mogacoService.getAllMogaco(); + } + + @Get('/:id') + async getMogacoById(@Param('id', ParseIntPipe) id: number): Promise { + return this.mogacoService.getMogacoById(id); + } +} diff --git a/app/backend/src/mogaco/mogaco.repository.ts b/app/backend/src/mogaco/mogaco.repository.ts new file mode 100644 index 000000000..54e47202f --- /dev/null +++ b/app/backend/src/mogaco/mogaco.repository.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@nestjs/common'; +import { PrismaService } from '../../libs/utils/prisma.service'; +import { Mogaco } from '@prisma/client'; + +@Injectable() +export class MogacoRepository { + constructor(private prisma: PrismaService) {} + + async getAllMogaco(): Promise { + return this.prisma.mogaco.findMany(); + } + + async getMogacoById(id: number): Promise { + return this.prisma.mogaco.findUnique({ + where: { id }, + }); + } +} diff --git a/app/backend/src/mogaco/mogaco.service.ts b/app/backend/src/mogaco/mogaco.service.ts new file mode 100644 index 000000000..9498947d1 --- /dev/null +++ b/app/backend/src/mogaco/mogaco.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@nestjs/common'; +import { MogacoRepository } from './mogaco.repository'; +import { Mogaco } from '@prisma/client'; + +@Injectable() +export class MogacoService { + constructor(private mogacoRepository: MogacoRepository) {} + + async getAllMogaco(): Promise { + return this.mogacoRepository.getAllMogaco(); + } + + async getMogacoById(id: number): Promise { + return this.mogacoRepository.getMogacoById(id); + } +} From aaef8d68bb98bbc864b5ca36cac5c9c819605d46 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 17:21:27 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=9D=BC,=20=EC=82=AD=EC=A0=9C=EC=9D=BC=20NULL=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/20231121065729_init/migration.sql | 11 +++++++++++ .../20231121065750_morak_0_0_2/migration.sql | 10 ++++++++++ app/backend/prisma/schema.prisma | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/backend/prisma/migrations/20231121065729_init/migration.sql create mode 100644 app/backend/prisma/migrations/20231121065750_morak_0_0_2/migration.sql diff --git a/app/backend/prisma/migrations/20231121065729_init/migration.sql b/app/backend/prisma/migrations/20231121065729_init/migration.sql new file mode 100644 index 000000000..d978c958d --- /dev/null +++ b/app/backend/prisma/migrations/20231121065729_init/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - You are about to alter the column `date` on the `Mogaco` table. The data in that column could be lost. The data in that column will be cast from `DateTime(0)` to `DateTime`. + - You are about to alter the column `deleted_at` on the `Mogaco` table. The data in that column could be lost. The data in that column will be cast from `DateTime(0)` to `DateTime`. + +*/ +-- AlterTable +ALTER TABLE `Mogaco` MODIFY `date` DATETIME NOT NULL, + MODIFY `updated_at` DATETIME(3) NULL, + MODIFY `deleted_at` DATETIME NULL; diff --git a/app/backend/prisma/migrations/20231121065750_morak_0_0_2/migration.sql b/app/backend/prisma/migrations/20231121065750_morak_0_0_2/migration.sql new file mode 100644 index 000000000..941ad318f --- /dev/null +++ b/app/backend/prisma/migrations/20231121065750_morak_0_0_2/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to alter the column `date` on the `Mogaco` table. The data in that column could be lost. The data in that column will be cast from `DateTime(0)` to `DateTime`. + - You are about to alter the column `deleted_at` on the `Mogaco` table. The data in that column could be lost. The data in that column will be cast from `DateTime(0)` to `DateTime`. + +*/ +-- AlterTable +ALTER TABLE `Mogaco` MODIFY `date` DATETIME NOT NULL, + MODIFY `deleted_at` DATETIME NULL; diff --git a/app/backend/prisma/schema.prisma b/app/backend/prisma/schema.prisma index b8083e51e..de37e12fb 100644 --- a/app/backend/prisma/schema.prisma +++ b/app/backend/prisma/schema.prisma @@ -31,8 +31,8 @@ model Mogaco { address String @db.VarChar(191) status String @db.VarChar(191) created_at DateTime @default(now()) - updated_at DateTime @updatedAt() - deleted_at DateTime @db.DateTime + updated_at DateTime? @updatedAt() + deleted_at DateTime? @db.DateTime mogacos Participant[] @@map("Mogaco") From e9382e4e59849ade5114554e165659c2f632c3e0 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 17:21:55 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=E2=9C=A8=20Mogaco=20Dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/mogaco/dto/create-mogaco.dto.ts | 11 +++++++++-- app/backend/src/mogaco/dto/index.ts | 2 ++ app/backend/src/mogaco/dto/mogaco.dto.ts | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/backend/src/mogaco/dto/index.ts create mode 100644 app/backend/src/mogaco/dto/mogaco.dto.ts diff --git a/app/backend/src/mogaco/dto/create-mogaco.dto.ts b/app/backend/src/mogaco/dto/create-mogaco.dto.ts index 493e10c46..29b58e1bc 100644 --- a/app/backend/src/mogaco/dto/create-mogaco.dto.ts +++ b/app/backend/src/mogaco/dto/create-mogaco.dto.ts @@ -1,6 +1,11 @@ -import { IsDateString, IsNotEmpty } from 'class-validator'; +import { IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional } from 'class-validator'; +import { MogacoStatus } from './mogaco-status.enum'; export class CreateMogacoDto { + @IsNotEmpty() + @IsInt() + group_id: number; + @IsNotEmpty() title: string; @@ -17,5 +22,7 @@ export class CreateMogacoDto { @IsNotEmpty() address: string; - status: string; + @IsOptional() + @IsEnum(MogacoStatus, { message: 'Invalid status' }) + status?: string; } diff --git a/app/backend/src/mogaco/dto/index.ts b/app/backend/src/mogaco/dto/index.ts new file mode 100644 index 000000000..0156e7892 --- /dev/null +++ b/app/backend/src/mogaco/dto/index.ts @@ -0,0 +1,2 @@ +export * from './create-mogaco.dto'; +export * from './mogaco.dto'; diff --git a/app/backend/src/mogaco/dto/mogaco.dto.ts b/app/backend/src/mogaco/dto/mogaco.dto.ts new file mode 100644 index 000000000..0e1160092 --- /dev/null +++ b/app/backend/src/mogaco/dto/mogaco.dto.ts @@ -0,0 +1,10 @@ +export class MogacoDto { + id: bigint; + group_id: bigint; + title: string; + contents: string; + date: Date; + max_human_count: number; + address: string; + status: string; +} From 7aa746659651a8c38413ac12c86c95944fc71c9b Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 17:22:06 +0900 Subject: [PATCH 7/8] =?UTF-8?q?=E2=9C=A8=20status-validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipes/mogaco-status-validation.pipe.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/backend/src/mogaco/pipes/mogaco-status-validation.pipe.ts diff --git a/app/backend/src/mogaco/pipes/mogaco-status-validation.pipe.ts b/app/backend/src/mogaco/pipes/mogaco-status-validation.pipe.ts new file mode 100644 index 000000000..d65801355 --- /dev/null +++ b/app/backend/src/mogaco/pipes/mogaco-status-validation.pipe.ts @@ -0,0 +1,21 @@ +import { BadRequestException, PipeTransform } from '@nestjs/common'; +import { MogacoStatus } from '../dto/mogaco-status.enum'; + +export class MogacoStatusValidationPipe implements PipeTransform { + readonly StatusOptions = [MogacoStatus.RECRUITING, MogacoStatus.CLOSED, MogacoStatus.COMPLETED]; + + transform(value: any) { + value = value.toUpperCase(); + + if (!this.isStatusValid(value)) { + throw new BadRequestException(`${value} isn't in the status options`); + } + + return value; + } + + private isStatusValid(status: any) { + const index = this.StatusOptions.indexOf(status); + return index !== -1; + } +} From 83f5e1bdd8d44a1ccfb322718b99830ffcff8cd3 Mon Sep 17 00:00:00 2001 From: DongHyeok Lim Date: Tue, 21 Nov 2023 17:22:48 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=E2=9C=A8=20=EB=AA=A8=EA=B0=81=EC=BD=94=20C?= =?UTF-8?q?RUD=20=EC=B4=88=EC=95=88=20=EC=84=A4=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 모각코 CRUD 초안 설계입니다. 사용자 인증에 대한 로직이 필요합니다. --- app/backend/src/mogaco/mogaco.controller.ts | 25 +++++++- app/backend/src/mogaco/mogaco.repository.ts | 70 ++++++++++++++++++++- app/backend/src/mogaco/mogaco.service.ts | 18 +++++- 3 files changed, 107 insertions(+), 6 deletions(-) diff --git a/app/backend/src/mogaco/mogaco.controller.ts b/app/backend/src/mogaco/mogaco.controller.ts index 800b5c597..3907e0c96 100644 --- a/app/backend/src/mogaco/mogaco.controller.ts +++ b/app/backend/src/mogaco/mogaco.controller.ts @@ -1,6 +1,9 @@ -import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from '@nestjs/common'; import { MogacoService } from './mogaco.service'; import { Mogaco } from '@prisma/client'; +import { CreateMogacoDto, MogacoDto } from './dto'; +import { MogacoStatusValidationPipe } from './pipes/mogaco-status-validation.pipe'; +import { MogacoStatus } from './dto/mogaco-status.enum'; @Controller('mogaco') export class MogacoController { @@ -12,7 +15,25 @@ export class MogacoController { } @Get('/:id') - async getMogacoById(@Param('id', ParseIntPipe) id: number): Promise { + async getMogacoById(@Param('id', ParseIntPipe) id: number): Promise { return this.mogacoService.getMogacoById(id); } + + @Post('/') + async createMogaco(@Body() createMogacoDto: CreateMogacoDto): Promise { + return this.mogacoService.createMogaco(createMogacoDto); + } + + @Delete('/:id') + async deleteMogaco(@Param('id', ParseIntPipe) id: number): Promise { + return this.mogacoService.deleteMogaco(id); + } + + @Patch('/:id/status') + updateMogacoStatus( + @Param('id', ParseIntPipe) id: number, + @Body('status', MogacoStatusValidationPipe) status: MogacoStatus, + ): Promise { + return this.mogacoService.updateMogacoStatus(id, status); + } } diff --git a/app/backend/src/mogaco/mogaco.repository.ts b/app/backend/src/mogaco/mogaco.repository.ts index 54e47202f..2a16ed3e3 100644 --- a/app/backend/src/mogaco/mogaco.repository.ts +++ b/app/backend/src/mogaco/mogaco.repository.ts @@ -1,6 +1,8 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; import { PrismaService } from '../../libs/utils/prisma.service'; import { Mogaco } from '@prisma/client'; +import { MogacoStatus } from './dto/mogaco-status.enum'; +import { CreateMogacoDto, MogacoDto } from './dto'; @Injectable() export class MogacoRepository { @@ -10,9 +12,71 @@ export class MogacoRepository { return this.prisma.mogaco.findMany(); } - async getMogacoById(id: number): Promise { - return this.prisma.mogaco.findUnique({ + async getMogacoById(id: number): Promise { + const mogaco = await this.prisma.mogaco.findUnique({ where: { id }, }); + + if (!mogaco) { + throw new NotFoundException(`Mogaco with id ${id} not found`); + } + + return { + id: mogaco.id, + group_id: mogaco.group_id, + title: mogaco.title, + contents: mogaco.contents, + date: mogaco.date, + max_human_count: mogaco.max_human_count, + address: mogaco.address, + status: mogaco.status, + }; + } + + async createMogaco(createMogacoDto: CreateMogacoDto): Promise { + try { + const { group_id, title, contents, max_human_count, address, date } = createMogacoDto; + + const mogaco = await this.prisma.mogaco.create({ + data: { + group_id, + title, + contents, + max_human_count, + address, + status: MogacoStatus.RECRUITING, + date: new Date(date), + }, + }); + + return mogaco; + } catch (error) { + throw new Error(`Failed to create Mogaco: ${error.message}`); + } + } + + async deleteMogaco(id: number): Promise { + const mogaco = await this.prisma.mogaco.findUnique({ + where: { id }, + }); + + if (!mogaco) { + throw new NotFoundException(`Mogaco with id ${id} not found`); + } + + await this.prisma.mogaco.delete({ + where: { id }, + }); + } + + async updateMogacoStatus(mogaco: MogacoDto): Promise { + try { + return await this.prisma.mogaco.update({ + where: { id: mogaco.id }, + data: { status: mogaco.status }, + }); + } catch (error) { + throw new Error(`Failed to update Mogaco status: ${error.message}`); + } } } diff --git a/app/backend/src/mogaco/mogaco.service.ts b/app/backend/src/mogaco/mogaco.service.ts index 9498947d1..a765e08ef 100644 --- a/app/backend/src/mogaco/mogaco.service.ts +++ b/app/backend/src/mogaco/mogaco.service.ts @@ -1,6 +1,8 @@ import { Injectable } from '@nestjs/common'; import { MogacoRepository } from './mogaco.repository'; import { Mogaco } from '@prisma/client'; +import { CreateMogacoDto, MogacoDto } from './dto'; +import { MogacoStatus } from './dto/mogaco-status.enum'; @Injectable() export class MogacoService { @@ -10,7 +12,21 @@ export class MogacoService { return this.mogacoRepository.getAllMogaco(); } - async getMogacoById(id: number): Promise { + async getMogacoById(id: number): Promise { return this.mogacoRepository.getMogacoById(id); } + + async createMogaco(createMogaco: CreateMogacoDto): Promise { + return this.mogacoRepository.createMogaco(createMogaco); + } + + async deleteMogaco(id: number): Promise { + return this.mogacoRepository.deleteMogaco(id); + } + + async updateMogacoStatus(id: number, status: MogacoStatus): Promise { + const mogaco = await this.getMogacoById(id); + mogaco.status = status; + return this.mogacoRepository.updateMogacoStatus(mogaco); + } }