Skip to content

Commit 9105eb5

Browse files
authored
Merge pull request #3030 from DFXswiss/develop
Release: develop -> main
2 parents 9530f0c + 6243948 commit 9105eb5

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/subdomains/core/history/controllers/transaction.controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,10 @@ export class TransactionController {
435435
@UseGuards(AuthGuard(), RoleGuard(UserRole.ACCOUNT), IpGuard, UserActiveGuard())
436436
@ApiOkResponse({ type: PdfDto })
437437
async generateInvoiceFromTransaction(@GetJwt() jwt: JwtPayload, @Param('id') id: string): Promise<PdfDto> {
438+
const txIdOrUid = isNaN(+id) ? id : +id;
438439
const txStatementDetails = await this.transactionHelper.getTxStatementDetails(
439440
jwt.account,
440-
+id,
441+
txIdOrUid,
441442
TxStatementType.INVOICE,
442443
);
443444

@@ -453,9 +454,10 @@ export class TransactionController {
453454
@UseGuards(AuthGuard(), RoleGuard(UserRole.ACCOUNT), IpGuard, UserActiveGuard())
454455
@ApiOkResponse({ type: PdfDto })
455456
async generateReceiptFromTransaction(@GetJwt() jwt: JwtPayload, @Param('id') id: string): Promise<PdfDto> {
457+
const txIdOrUid = isNaN(+id) ? id : +id;
456458
const txStatementDetails = await this.transactionHelper.getTxStatementDetails(
457459
jwt.account,
458-
+id,
460+
txIdOrUid,
459461
TxStatementType.RECEIPT,
460462
);
461463

src/subdomains/supporting/payment/services/transaction-helper.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,20 +493,26 @@ export class TransactionHelper implements OnModuleInit {
493493

494494
async getTxStatementDetails(
495495
userDataId: number,
496-
txId: number,
496+
txIdOrUid: number | string,
497497
statementType: TxStatementType,
498498
): Promise<TxStatementDetails> {
499-
const transaction = await this.transactionService.getTransactionById(txId, {
499+
const relations = {
500500
userData: { organization: true },
501501
buyCrypto: { buy: { user: { wallet: true } }, cryptoRoute: true, cryptoInput: true },
502502
buyFiat: { sell: true, cryptoInput: true },
503503
refReward: { user: { userData: true } },
504-
});
504+
};
505+
506+
const transaction =
507+
typeof txIdOrUid === 'number'
508+
? await this.transactionService.getTransactionById(txIdOrUid, relations)
509+
: await this.transactionService.getTransactionByUid(txIdOrUid, relations);
505510

506511
if (!transaction || !transaction.targetEntity || transaction.targetEntity instanceof BankTxReturn)
507512
throw new BadRequestException('Transaction not found');
508513
if (!transaction.userData.isDataComplete) throw new BadRequestException('User data is not complete');
509-
if (!transaction.targetEntity.isComplete) throw new BadRequestException('Transaction not completed');
514+
if (statementType === TxStatementType.RECEIPT && !transaction.targetEntity.isComplete)
515+
throw new BadRequestException('Transaction not completed');
510516
if (transaction.userData.id !== userDataId) throw new ForbiddenException('Not your transaction');
511517

512518
if (transaction.buyCrypto && !transaction.buyCrypto.isCryptoCryptoTransaction) {

0 commit comments

Comments
 (0)