From de206502b927c5304f49c1b1234ac38b0b43bf73 Mon Sep 17 00:00:00 2001 From: ssoxong Date: Wed, 1 May 2024 11:00:46 +0900 Subject: [PATCH] feat: getTransactionsByEvent --- src/group/group.controller.ts | 13 +++++++++++++ src/group/group.service.ts | 20 +++++++++++++++++++- src/transaction/transaction.repository.ts | 8 ++++---- src/transaction/transaction.service.ts | 7 ++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/group/group.controller.ts b/src/group/group.controller.ts index 13726ce..2e6809f 100644 --- a/src/group/group.controller.ts +++ b/src/group/group.controller.ts @@ -165,6 +165,19 @@ export class GroupController { return this.groupService.getTransactions(groupId); } + @Get(':groupId/transaction/event') + @Transaction() + @ApiOperation({ + summary: '모임 이벤트 거래내역 조회', + description: '모임의 특정 이벤트의 거래내역을 조회합니다.', + }) + getTransactionsByEvent( + @Param('groupId') groupId: string, + @Query('eventId') eventId: string, + ) { + return this.groupService.getTransactionsByEvent(groupId, eventId); + } + @Get(':groupId/transaction/period') @Transaction() @ApiOperation({ diff --git a/src/group/group.service.ts b/src/group/group.service.ts index bce308e..93f7f6f 100644 --- a/src/group/group.service.ts +++ b/src/group/group.service.ts @@ -118,11 +118,29 @@ export class GroupService { return this.transactionService.getTransactions(groupId); } + async getTransactionsByEvent(groupId: string, eventId: string) { + //eventId로 eventTransaction 정보 가져오기 + const event = await this.eventService.getOne(eventId); + // startTransactionDate, endTransactionDate로 변경 필요 + const eventStart = event.startDate; + const eventEnd = event.endDate; + + return this.transactionService.getTransactionsByPeriod( + groupId, + eventStart, + eventEnd, + ); + } + async getTransactionsByPeriod( groupId: string, periodDto: GetTransactionsPeriodDto, ) { - return this.transactionService.getTransactionsByPeriod(groupId, periodDto); + return this.transactionService.getTransactionsByPeriod( + groupId, + periodDto.startDate, + periodDto.endDate, + ); } async update( diff --git a/src/transaction/transaction.repository.ts b/src/transaction/transaction.repository.ts index 4cfc3f9..820caf5 100644 --- a/src/transaction/transaction.repository.ts +++ b/src/transaction/transaction.repository.ts @@ -1,7 +1,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; -import { GetTransactionsPeriodDto } from './dto/get-transaction-period-dto'; import { Transaction } from './entities/transaction.entity'; import { TransactionInterface } from './interfaces/transaction.interface'; @@ -22,14 +21,15 @@ export class TransactionRepository { async getTransactionsByPeriod( groupId: string, - periodDto: GetTransactionsPeriodDto, + startDate: Date, + endDate: Date, ): Promise { return this.transactionModel .find({ 'metadata.groupId': groupId, timestamp: { - $gte: new Date(periodDto.startDate), - $lt: new Date(periodDto.endDate), + $gte: new Date(startDate), + $lt: new Date(endDate), }, }) .exec(); diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index d706690..93f9384 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@nestjs/common'; import { ExcelService } from '../excel/excel.service'; -import { GetTransactionsPeriodDto } from './dto/get-transaction-period-dto'; import { Transaction } from './entities/transaction.entity'; import { TransactionRepository } from './transaction.repository'; @@ -36,11 +35,13 @@ export class TransactionService { async getTransactionsByPeriod( groupId: string, - periodDto: GetTransactionsPeriodDto, + startDate: Date, + endDate: Date, ) { return this.transactionRepository.getTransactionsByPeriod( groupId, - periodDto, + startDate, + endDate, ); } }