rwadurian/backend/services/planting-service/src/domain/value-objects/fund-allocation.vo.ts

39 lines
990 B
TypeScript

import { FundAllocationTargetType } from './fund-allocation-target-type.enum';
export interface FundAllocationDTO {
targetType: FundAllocationTargetType;
amount: number;
targetAccountId: string | null;
metadata?: Record<string, unknown>;
}
export class FundAllocation {
constructor(
public readonly targetType: FundAllocationTargetType,
public readonly amount: number,
public readonly targetAccountId: string | null,
public readonly metadata?: Record<string, unknown>,
) {
if (amount < 0) {
throw new Error('分配金额不能为负数');
}
}
toDTO(): FundAllocationDTO {
return {
targetType: this.targetType,
amount: this.amount,
targetAccountId: this.targetAccountId,
metadata: this.metadata,
};
}
equals(other: FundAllocation): boolean {
return (
this.targetType === other.targetType &&
this.amount === other.amount &&
this.targetAccountId === other.targetAccountId
);
}
}