Skip to content

Commit 37e3b1f

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 1bb82f7 commit 37e3b1f

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable @typescript-eslint/no-inferrable-types */
2+
import { Type } from 'class-transformer';
3+
import { IsNumber } from 'class-validator';
4+
5+
export class GetManyForexOrdersInputDto {
6+
@IsNumber()
7+
@Type(() => Number)
8+
page: number = 1;
9+
10+
@IsNumber()
11+
@Type(() => Number)
12+
limit: number = 10;
13+
}

apps/transaction/src/app/transactions/transactions.controller.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common';
1+
import {
2+
Body,
3+
Controller,
4+
Get,
5+
Param,
6+
Post,
7+
Query,
8+
UseGuards,
9+
} from '@nestjs/common';
210
import {
311
ApiBadRequestResponse,
412
ApiCookieAuth,
@@ -12,6 +20,7 @@ import { ResponseErrorEntity, ValidationErrorEntity } from '@square-me/nestjs';
1220
import { TransactionsService } from './transactions.service';
1321
import { FundWalletInputDto } from './dto/fund-wallet-input.dto';
1422
import { WithdrawWalletInputDto } from './dto/debit-wallet-input.dto';
23+
import { GetManyForexOrdersInputDto } from './dto/get-many-forex-orders-input.dto';
1524
@Controller({ version: '1', path: 'transactions' })
1625
@UseGuards(AuthServiceGuard)
1726
@ApiTags('Transactions')
@@ -68,4 +77,12 @@ export class TransactionsController {
6877
);
6978
return response;
7079
}
80+
81+
@Get('forex-orders')
82+
async getManyForexOrder(
83+
@CurrentUser() user: GrpcUser,
84+
@Query() inputDto: GetManyForexOrdersInputDto
85+
) {
86+
return this.transactionService.getManyForexOrder(user.id, inputDto);
87+
}
7188
}

apps/transaction/src/app/transactions/transactions.service.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ import {
3434
} from '../../typeorm/models/enums';
3535
import { RetryOrderProducer } from './retry-order.producer';
3636
import { NOTIFICATION_CLIENT } from '@square-me/microservice-client';
37+
import {
38+
paginate,
39+
Pagination,
40+
IPaginationOptions,
41+
} from 'nestjs-typeorm-paginate';
3742

3843
type BuyForexServiceOptions = BuyForexInputDto & {
3944
userId: string;
@@ -81,6 +86,12 @@ export class TransactionsService implements OnModuleInit {
8186
this.getOrCreateIntegrationService();
8287
}
8388

89+
async paginateForexOrders(
90+
options: IPaginationOptions
91+
): Promise<Pagination<ForexOrder>> {
92+
return paginate<ForexOrder>(this.forexOrderRepo, options);
93+
}
94+
8495
private getOrCreateWalletService() {
8596
if (!this.walletService) {
8697
this.walletService =
@@ -376,4 +387,16 @@ export class TransactionsService implements OnModuleInit {
376387
async withdrawWallet(userId: string, walletId: string, amount: string) {
377388
return await this.processWalletWithdrawal({ userId, walletId, amount });
378389
}
390+
391+
async getManyForexOrder(
392+
userId: string,
393+
{ page, limit }: { page: number; limit: number }
394+
) {
395+
const queryBuilder = this.forexOrderRepo
396+
.createQueryBuilder('f')
397+
.where('f.userId = :id', { id: userId })
398+
.orderBy('f.createdAt', 'DESC');
399+
400+
return paginate<ForexOrder>(queryBuilder, { page, limit });
401+
}
379402
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@nestjs/typeorm": "^11.0.0",
3030
"amqp-connection-manager": "^4.1.14",
3131
"amqplib": "^0.10.8",
32+
"argon2": "^0.43.0",
3233
"axios": "^1.9.0",
3334
"bullmq": "^5.52.2",
3435
"class-transformer": "^0.5.1",
@@ -42,6 +43,7 @@
4243
"ioredis": "^5.6.1",
4344
"nest-commander": "^3.17.0",
4445
"nestjs-pino": "^4.4.0",
46+
"nestjs-typeorm-paginate": "^4.1.0",
4547
"nodemailer": "^7.0.3",
4648
"pg": "^8.15.6",
4749
"pino": "^9.6.0",
@@ -51,7 +53,6 @@
5153
"ts-proto": "^2.7.0",
5254
"tslib": "^2.3.0",
5355
"typeorm": "^0.3.23",
54-
"argon2": "^0.43.0",
5556
"uuid": "^11.1.0"
5657
},
5758
"devDependencies": {

pnpm-lock.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)