wip
This commit is contained in:
@@ -16,7 +16,7 @@ export interface PrizeProps {
|
||||
seasonId: string;
|
||||
position: number;
|
||||
amount: Money;
|
||||
driverId?: string;
|
||||
driverId: string;
|
||||
status: PrizeStatus;
|
||||
createdAt: Date;
|
||||
awardedAt: Date | undefined;
|
||||
@@ -29,7 +29,7 @@ export class Prize implements IEntity<string> {
|
||||
readonly seasonId: string;
|
||||
readonly position: number;
|
||||
readonly amount: Money;
|
||||
readonly driverId: string | undefined;
|
||||
readonly driverId: string;
|
||||
readonly status: PrizeStatus;
|
||||
readonly createdAt: Date;
|
||||
readonly awardedAt: Date | undefined;
|
||||
@@ -49,14 +49,26 @@ export class Prize implements IEntity<string> {
|
||||
this.description = props.description;
|
||||
}
|
||||
|
||||
static create(props: Omit<PrizeProps, 'createdAt' | 'status'> & {
|
||||
static create(props: Omit<PrizeProps, 'createdAt' | 'status' | 'driverId' | 'awardedAt' | 'paidAt' | 'description'> & {
|
||||
createdAt?: Date;
|
||||
status?: PrizeStatus;
|
||||
driverId?: string;
|
||||
awardedAt?: Date;
|
||||
paidAt?: Date;
|
||||
description?: string;
|
||||
}): Prize {
|
||||
this.validate(props);
|
||||
const fullProps: Omit<PrizeProps, 'createdAt' | 'status'> = {
|
||||
...props,
|
||||
driverId: props.driverId ?? '',
|
||||
awardedAt: props.awardedAt,
|
||||
paidAt: props.paidAt,
|
||||
description: props.description,
|
||||
};
|
||||
|
||||
this.validate(fullProps);
|
||||
|
||||
return new Prize({
|
||||
...props,
|
||||
...fullProps,
|
||||
createdAt: props.createdAt ?? new Date(),
|
||||
status: props.status ?? 'pending',
|
||||
});
|
||||
@@ -112,7 +124,7 @@ export class Prize implements IEntity<string> {
|
||||
throw new RacingDomainInvariantError('Only awarded prizes can be marked as paid');
|
||||
}
|
||||
|
||||
if (!this.driverId) {
|
||||
if (!this.driverId || this.driverId.trim() === '') {
|
||||
throw new RacingDomainInvariantError('Prize must have a driver to be paid');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user