inmemory to postgres
This commit is contained in:
@@ -8,8 +8,8 @@ import { RacingDomainValidationError, RacingDomainInvariantError } from '../../e
|
||||
|
||||
import type { Money } from '../../value-objects/Money';
|
||||
import type { IEntity } from '@core/shared/domain';
|
||||
import type { TransactionId } from './TransactionId';
|
||||
import type { LeagueWalletId } from './LeagueWalletId';
|
||||
import { TransactionId } from './TransactionId';
|
||||
import { LeagueWalletId } from './LeagueWalletId';
|
||||
|
||||
export type TransactionType =
|
||||
| 'sponsorship_payment'
|
||||
@@ -79,6 +79,34 @@ export class Transaction implements IEntity<TransactionId> {
|
||||
});
|
||||
}
|
||||
|
||||
static rehydrate(props: {
|
||||
id: string;
|
||||
walletId: string;
|
||||
type: TransactionType;
|
||||
amount: Money;
|
||||
platformFee: Money;
|
||||
netAmount: Money;
|
||||
status: TransactionStatus;
|
||||
createdAt: Date;
|
||||
completedAt?: Date;
|
||||
description?: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
}): Transaction {
|
||||
return new Transaction({
|
||||
id: TransactionId.create(props.id),
|
||||
walletId: LeagueWalletId.create(props.walletId),
|
||||
type: props.type,
|
||||
amount: props.amount,
|
||||
platformFee: props.platformFee,
|
||||
netAmount: props.netAmount,
|
||||
status: props.status,
|
||||
createdAt: props.createdAt,
|
||||
completedAt: props.completedAt,
|
||||
description: props.description,
|
||||
metadata: props.metadata,
|
||||
});
|
||||
}
|
||||
|
||||
private static validate(props: Omit<TransactionProps, 'createdAt' | 'status' | 'platformFee' | 'netAmount'>): void {
|
||||
if (!props.id) {
|
||||
throw new RacingDomainValidationError('Transaction ID is required');
|
||||
|
||||
Reference in New Issue
Block a user