Skip to content

Commit

Permalink
feat: getTransactionsByEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoxong committed May 1, 2024
1 parent b9904d9 commit de20650
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
20 changes: 19 additions & 1 deletion src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/transaction/transaction.repository.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -22,14 +21,15 @@ export class TransactionRepository {

async getTransactionsByPeriod(
groupId: string,
periodDto: GetTransactionsPeriodDto,
startDate: Date,
endDate: Date,
): Promise<any> {
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();
Expand Down
7 changes: 4 additions & 3 deletions src/transaction/transaction.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
);
}
}

0 comments on commit de20650

Please sign in to comment.