Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,10 @@ export class TransactionController {
@UseGuards(AuthGuard(), RoleGuard(UserRole.ACCOUNT), IpGuard, UserActiveGuard())
@ApiOkResponse({ type: PdfDto })
async generateInvoiceFromTransaction(@GetJwt() jwt: JwtPayload, @Param('id') id: string): Promise<PdfDto> {
const txIdOrUid = isNaN(+id) ? id : +id;
const txStatementDetails = await this.transactionHelper.getTxStatementDetails(
jwt.account,
+id,
txIdOrUid,
TxStatementType.INVOICE,
);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,20 +493,26 @@ export class TransactionHelper implements OnModuleInit {

async getTxStatementDetails(
userDataId: number,
txId: number,
txIdOrUid: number | string,
statementType: TxStatementType,
): Promise<TxStatementDetails> {
const transaction = await this.transactionService.getTransactionById(txId, {
const relations = {
userData: { organization: true },
buyCrypto: { buy: { user: { wallet: true } }, cryptoRoute: true, cryptoInput: true },
buyFiat: { sell: true, cryptoInput: true },
refReward: { user: { userData: true } },
});
};

const transaction =
typeof txIdOrUid === 'number'
? await this.transactionService.getTransactionById(txIdOrUid, relations)
: await this.transactionService.getTransactionByUid(txIdOrUid, relations);

if (!transaction || !transaction.targetEntity || transaction.targetEntity instanceof BankTxReturn)
throw new BadRequestException('Transaction not found');
if (!transaction.userData.isDataComplete) throw new BadRequestException('User data is not complete');
if (!transaction.targetEntity.isComplete) throw new BadRequestException('Transaction not completed');
if (statementType === TxStatementType.RECEIPT && !transaction.targetEntity.isComplete)
throw new BadRequestException('Transaction not completed');
if (transaction.userData.id !== userDataId) throw new ForbiddenException('Not your transaction');

if (transaction.buyCrypto && !transaction.buyCrypto.isCryptoCryptoTransaction) {
Expand Down
Loading