Skip to content

Commit

Permalink
List transactions by account
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Goncalves committed Mar 9, 2024
1 parent cc973dd commit c5e621f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/controller/monetary-transaction.controller.ts
Expand Up @@ -37,6 +37,11 @@ export class MonetaryTransactionController {
return this.transactionService.findAll();
}

@Get("/account/:id")
findAllForAccount(@Param('id', ParseIntPipe) accountId: number) {
return this.transactionService.findAllForAccount(accountId);
}

@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {
return this.transactionService.findOne(id);
Expand Down
15 changes: 15 additions & 0 deletions src/domain/monetary-transaction.service.ts
Expand Up @@ -8,6 +8,8 @@ import { Category } from './category.entity';

@Injectable()
export class MonetaryTransactionService {


constructor(
@InjectRepository(MonetaryTransaction)
private transactionsRepository: Repository<MonetaryTransaction>,
Expand Down Expand Up @@ -43,6 +45,19 @@ export class MonetaryTransactionService {
return this.transactionsRepository.find();
}

findAllForAccount(accountId: number) {
return this.transactionsRepository.find({
relations: {
account: true,
},
where: {
account: {
id: accountId,
},
}
});
}

findOne(id: number) {
return this.transactionsRepository.findOneBy({ id });
}
Expand Down
File renamed without changes.

0 comments on commit c5e621f

Please sign in to comment.