mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-10 15:21:45 +00:00
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
import { Transaction } from '~/card/entities/transaction.entity';
|
|
|
|
export class TransactionDetailResponseDto {
|
|
@ApiProperty()
|
|
id!: string;
|
|
|
|
@ApiProperty({ example: '2025-10-14T09:53:40.000Z' })
|
|
date!: Date;
|
|
|
|
@ApiProperty({ example: 50.5 })
|
|
amount!: number;
|
|
|
|
@ApiProperty({ example: 'SAR' })
|
|
currency!: string;
|
|
|
|
@ApiProperty({ example: 2.5 })
|
|
fees!: number;
|
|
|
|
@ApiProperty({ example: 0.5 })
|
|
vatOnFees!: number;
|
|
|
|
@ApiPropertyOptional({ example: 'Target Store' })
|
|
merchantName!: string | null;
|
|
|
|
@ApiPropertyOptional({ example: 'Shopping' })
|
|
category!: string | null;
|
|
|
|
@ApiPropertyOptional({ example: 'Riyadh' })
|
|
merchantCity!: string | null;
|
|
|
|
@ApiProperty({ example: '277012*****3456' })
|
|
cardMasked!: string;
|
|
|
|
@ApiProperty()
|
|
rrn!: string;
|
|
|
|
@ApiProperty()
|
|
transactionId!: string;
|
|
|
|
constructor(transaction: Transaction) {
|
|
this.id = transaction.id;
|
|
this.date = transaction.transactionDate;
|
|
this.amount = transaction.transactionAmount;
|
|
this.currency = transaction.transactionCurrency === '682' ? 'SAR' : transaction.transactionCurrency;
|
|
this.fees = transaction.fees;
|
|
this.vatOnFees = transaction.vatOnFees;
|
|
this.merchantName = transaction.merchantName;
|
|
this.category = this.mapMccToCategory(transaction.merchantCategoryCode);
|
|
this.merchantCity = transaction.merchantCity;
|
|
this.cardMasked = transaction.cardMaskedNumber;
|
|
this.rrn = transaction.rrn;
|
|
this.transactionId = transaction.transactionId;
|
|
}
|
|
|
|
private mapMccToCategory(mcc: string | null): string {
|
|
if (!mcc) return 'Other';
|
|
|
|
const mccCode = mcc;
|
|
|
|
// Map MCC codes to categories
|
|
if (mccCode >= '5200' && mccCode <= '5599') return 'Shopping';
|
|
if (mccCode >= '5800' && mccCode <= '5899') return 'Food & Dining';
|
|
if (mccCode >= '3000' && mccCode <= '3999') return 'Travel';
|
|
if (mccCode >= '4000' && mccCode <= '4799') return 'Transportation';
|
|
if (mccCode >= '7200' && mccCode <= '7999') return 'Entertainment';
|
|
if (mccCode >= '5900' && mccCode <= '5999') return 'Services';
|
|
if (mccCode >= '4800' && mccCode <= '4899') return 'Utilities';
|
|
if (mccCode >= '8000' && mccCode <= '8999') return 'Health & Wellness';
|
|
|
|
return 'Other';
|
|
}
|
|
}
|
|
|