mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
import { Transaction } from '~/card/entities/transaction.entity';
|
|
|
|
export class SpendingHistoryItemDto {
|
|
@ApiProperty({ example: '2025-10-14T09:53:40.000Z' })
|
|
date!: Date;
|
|
|
|
@ApiProperty({ example: 50.5 })
|
|
amount!: number;
|
|
|
|
@ApiProperty({ example: 'SAR' })
|
|
currency!: string;
|
|
|
|
@ApiPropertyOptional({ example: 'Shopping' })
|
|
category!: string | null;
|
|
|
|
@ApiPropertyOptional({ example: 'Target Store' })
|
|
merchantName!: string | null;
|
|
|
|
@ApiPropertyOptional({ example: 'Riyadh' })
|
|
merchantCity!: string | null;
|
|
|
|
@ApiProperty({ example: '277012*****3456' })
|
|
cardMasked!: string;
|
|
|
|
@ApiProperty()
|
|
transactionId!: string;
|
|
|
|
constructor(transaction: Transaction) {
|
|
this.date = transaction.transactionDate;
|
|
this.amount = transaction.transactionAmount;
|
|
this.currency = transaction.transactionCurrency === '682' ? 'SAR' : transaction.transactionCurrency;
|
|
this.category = this.mapMccToCategory(transaction.merchantCategoryCode);
|
|
this.merchantName = transaction.merchantName;
|
|
this.merchantCity = transaction.merchantCity;
|
|
this.cardMasked = transaction.cardMaskedNumber;
|
|
this.transactionId = transaction.id;
|
|
}
|
|
|
|
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';
|
|
}
|
|
}
|
|
|