refactor
This commit is contained in:
21
core/payments/domain/entities/MemberPayment.ts
Normal file
21
core/payments/domain/entities/MemberPayment.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Domain Entity: MemberPayment
|
||||
*/
|
||||
|
||||
export enum MemberPaymentStatus {
|
||||
PENDING = 'pending',
|
||||
PAID = 'paid',
|
||||
OVERDUE = 'overdue',
|
||||
}
|
||||
|
||||
export interface MemberPayment {
|
||||
id: string;
|
||||
feeId: string;
|
||||
driverId: string;
|
||||
amount: number;
|
||||
platformFee: number;
|
||||
netAmount: number;
|
||||
status: MemberPaymentStatus;
|
||||
dueDate: Date;
|
||||
paidAt?: Date;
|
||||
}
|
||||
20
core/payments/domain/entities/MembershipFee.ts
Normal file
20
core/payments/domain/entities/MembershipFee.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Domain Entity: MembershipFee
|
||||
*/
|
||||
|
||||
export enum MembershipFeeType {
|
||||
SEASON = 'season',
|
||||
MONTHLY = 'monthly',
|
||||
PER_RACE = 'per_race',
|
||||
}
|
||||
|
||||
export interface MembershipFee {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
seasonId?: string;
|
||||
type: MembershipFeeType;
|
||||
amount: number;
|
||||
enabled: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
35
core/payments/domain/entities/Payment.ts
Normal file
35
core/payments/domain/entities/Payment.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Domain Entity: Payment
|
||||
*/
|
||||
|
||||
export enum PaymentType {
|
||||
SPONSORSHIP = 'sponsorship',
|
||||
MEMBERSHIP_FEE = 'membership_fee',
|
||||
}
|
||||
|
||||
export enum PayerType {
|
||||
SPONSOR = 'sponsor',
|
||||
DRIVER = 'driver',
|
||||
}
|
||||
|
||||
export enum PaymentStatus {
|
||||
PENDING = 'pending',
|
||||
COMPLETED = 'completed',
|
||||
FAILED = 'failed',
|
||||
REFUNDED = 'refunded',
|
||||
}
|
||||
|
||||
export interface Payment {
|
||||
id: string;
|
||||
type: PaymentType;
|
||||
amount: number;
|
||||
platformFee: number;
|
||||
netAmount: number;
|
||||
payerId: string;
|
||||
payerType: PayerType;
|
||||
leagueId: string;
|
||||
seasonId?: string;
|
||||
status: PaymentStatus;
|
||||
createdAt: Date;
|
||||
completedAt?: Date;
|
||||
}
|
||||
24
core/payments/domain/entities/Prize.ts
Normal file
24
core/payments/domain/entities/Prize.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Domain Entity: Prize
|
||||
*/
|
||||
|
||||
export enum PrizeType {
|
||||
CASH = 'cash',
|
||||
MERCHANDISE = 'merchandise',
|
||||
OTHER = 'other',
|
||||
}
|
||||
|
||||
export interface Prize {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
seasonId: string;
|
||||
position: number;
|
||||
name: string;
|
||||
amount: number;
|
||||
type: PrizeType;
|
||||
description?: string;
|
||||
awarded: boolean;
|
||||
awardedTo?: string;
|
||||
awardedAt?: Date;
|
||||
createdAt: Date;
|
||||
}
|
||||
37
core/payments/domain/entities/Wallet.ts
Normal file
37
core/payments/domain/entities/Wallet.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Domain Entity: Wallet
|
||||
*/
|
||||
|
||||
export interface Wallet {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
balance: number;
|
||||
totalRevenue: number;
|
||||
totalPlatformFees: number;
|
||||
totalWithdrawn: number;
|
||||
currency: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export enum TransactionType {
|
||||
DEPOSIT = 'deposit',
|
||||
WITHDRAWAL = 'withdrawal',
|
||||
PLATFORM_FEE = 'platform_fee',
|
||||
}
|
||||
|
||||
export enum ReferenceType {
|
||||
SPONSORSHIP = 'sponsorship',
|
||||
MEMBERSHIP_FEE = 'membership_fee',
|
||||
PRIZE = 'prize',
|
||||
}
|
||||
|
||||
export interface Transaction {
|
||||
id: string;
|
||||
walletId: string;
|
||||
type: TransactionType;
|
||||
amount: number;
|
||||
description: string;
|
||||
referenceId?: string;
|
||||
referenceType?: ReferenceType;
|
||||
createdAt: Date;
|
||||
}
|
||||
5
core/payments/domain/entities/index.ts
Normal file
5
core/payments/domain/entities/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './Payment';
|
||||
export * from './MembershipFee';
|
||||
export * from './MemberPayment';
|
||||
export * from './Prize';
|
||||
export * from './Wallet';
|
||||
2
core/payments/domain/index.ts
Normal file
2
core/payments/domain/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './entities';
|
||||
export * from './repositories';
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Repository Interface: IMembershipFeeRepository
|
||||
*/
|
||||
|
||||
import type { MembershipFee } from '../entities/MembershipFee';
|
||||
import type { MemberPayment } from '../entities/MemberPayment';
|
||||
|
||||
export interface IMembershipFeeRepository {
|
||||
findById(id: string): Promise<MembershipFee | null>;
|
||||
findByLeagueId(leagueId: string): Promise<MembershipFee | null>;
|
||||
create(fee: MembershipFee): Promise<MembershipFee>;
|
||||
update(fee: MembershipFee): Promise<MembershipFee>;
|
||||
}
|
||||
|
||||
export interface IMemberPaymentRepository {
|
||||
findById(id: string): Promise<MemberPayment | null>;
|
||||
findByFeeIdAndDriverId(feeId: string, driverId: string): Promise<MemberPayment | null>;
|
||||
findByLeagueIdAndDriverId(leagueId: string, driverId: string, membershipFeeRepo: IMembershipFeeRepository): Promise<MemberPayment[]>;
|
||||
create(payment: MemberPayment): Promise<MemberPayment>;
|
||||
update(payment: MemberPayment): Promise<MemberPayment>;
|
||||
}
|
||||
15
core/payments/domain/repositories/IPaymentRepository.ts
Normal file
15
core/payments/domain/repositories/IPaymentRepository.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Repository Interface: IPaymentRepository
|
||||
*/
|
||||
|
||||
import type { Payment, PaymentType } from '../entities/Payment';
|
||||
|
||||
export interface IPaymentRepository {
|
||||
findById(id: string): Promise<Payment | null>;
|
||||
findByLeagueId(leagueId: string): Promise<Payment[]>;
|
||||
findByPayerId(payerId: string): Promise<Payment[]>;
|
||||
findByType(type: PaymentType): Promise<Payment[]>;
|
||||
findByFilters(filters: { leagueId?: string; payerId?: string; type?: PaymentType }): Promise<Payment[]>;
|
||||
create(payment: Payment): Promise<Payment>;
|
||||
update(payment: Payment): Promise<Payment>;
|
||||
}
|
||||
15
core/payments/domain/repositories/IPrizeRepository.ts
Normal file
15
core/payments/domain/repositories/IPrizeRepository.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Repository Interface: IPrizeRepository
|
||||
*/
|
||||
|
||||
import type { Prize } from '../entities/Prize';
|
||||
|
||||
export interface IPrizeRepository {
|
||||
findById(id: string): Promise<Prize | null>;
|
||||
findByLeagueId(leagueId: string): Promise<Prize[]>;
|
||||
findByLeagueIdAndSeasonId(leagueId: string, seasonId: string): Promise<Prize[]>;
|
||||
findByPosition(leagueId: string, seasonId: string, position: number): Promise<Prize | null>;
|
||||
create(prize: Prize): Promise<Prize>;
|
||||
update(prize: Prize): Promise<Prize>;
|
||||
delete(id: string): Promise<void>;
|
||||
}
|
||||
18
core/payments/domain/repositories/IWalletRepository.ts
Normal file
18
core/payments/domain/repositories/IWalletRepository.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Repository Interface: IWalletRepository
|
||||
*/
|
||||
|
||||
import type { Wallet, Transaction } from '../entities/Wallet';
|
||||
|
||||
export interface IWalletRepository {
|
||||
findById(id: string): Promise<Wallet | null>;
|
||||
findByLeagueId(leagueId: string): Promise<Wallet | null>;
|
||||
create(wallet: Wallet): Promise<Wallet>;
|
||||
update(wallet: Wallet): Promise<Wallet>;
|
||||
}
|
||||
|
||||
export interface ITransactionRepository {
|
||||
findById(id: string): Promise<Transaction | null>;
|
||||
findByWalletId(walletId: string): Promise<Transaction[]>;
|
||||
create(transaction: Transaction): Promise<Transaction>;
|
||||
}
|
||||
4
core/payments/domain/repositories/index.ts
Normal file
4
core/payments/domain/repositories/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './IPaymentRepository';
|
||||
export * from './IMembershipFeeRepository';
|
||||
export * from './IPrizeRepository';
|
||||
export * from './IWalletRepository';
|
||||
Reference in New Issue
Block a user