wip
This commit is contained in:
@@ -36,12 +36,12 @@ export class SponsorshipRequest implements IEntity<string> {
|
||||
readonly entityId: string;
|
||||
readonly tier: SponsorshipTier;
|
||||
readonly offeredAmount: Money;
|
||||
readonly message?: string;
|
||||
readonly message: string | undefined;
|
||||
readonly status: SponsorshipRequestStatus;
|
||||
readonly createdAt: Date;
|
||||
readonly respondedAt?: Date;
|
||||
readonly respondedBy?: string;
|
||||
readonly rejectionReason?: string;
|
||||
readonly respondedAt: Date | undefined;
|
||||
readonly respondedBy: string | undefined;
|
||||
readonly rejectionReason: string | undefined;
|
||||
|
||||
private constructor(props: SponsorshipRequestProps) {
|
||||
this.id = props.id;
|
||||
@@ -113,12 +113,28 @@ export class SponsorshipRequest implements IEntity<string> {
|
||||
throw new RacingDomainValidationError('respondedBy is required when accepting');
|
||||
}
|
||||
|
||||
return new SponsorshipRequest({
|
||||
...this,
|
||||
const base: SponsorshipRequestProps = {
|
||||
id: this.id,
|
||||
sponsorId: this.sponsorId,
|
||||
entityType: this.entityType,
|
||||
entityId: this.entityId,
|
||||
tier: this.tier,
|
||||
offeredAmount: this.offeredAmount,
|
||||
status: 'accepted',
|
||||
createdAt: this.createdAt,
|
||||
respondedAt: new Date(),
|
||||
respondedBy,
|
||||
});
|
||||
};
|
||||
|
||||
const withMessage =
|
||||
this.message !== undefined ? { ...base, message: this.message } : base;
|
||||
|
||||
const next: SponsorshipRequestProps =
|
||||
this.rejectionReason !== undefined
|
||||
? { ...withMessage, rejectionReason: this.rejectionReason }
|
||||
: withMessage;
|
||||
|
||||
return new SponsorshipRequest(next);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,13 +149,26 @@ export class SponsorshipRequest implements IEntity<string> {
|
||||
throw new RacingDomainValidationError('respondedBy is required when rejecting');
|
||||
}
|
||||
|
||||
return new SponsorshipRequest({
|
||||
...this,
|
||||
const base: SponsorshipRequestProps = {
|
||||
id: this.id,
|
||||
sponsorId: this.sponsorId,
|
||||
entityType: this.entityType,
|
||||
entityId: this.entityId,
|
||||
tier: this.tier,
|
||||
offeredAmount: this.offeredAmount,
|
||||
status: 'rejected',
|
||||
createdAt: this.createdAt,
|
||||
respondedAt: new Date(),
|
||||
respondedBy,
|
||||
rejectionReason: reason,
|
||||
});
|
||||
};
|
||||
|
||||
const withMessage =
|
||||
this.message !== undefined ? { ...base, message: this.message } : base;
|
||||
|
||||
const next: SponsorshipRequestProps =
|
||||
reason !== undefined ? { ...withMessage, rejectionReason: reason } : withMessage;
|
||||
|
||||
return new SponsorshipRequest(next);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,11 +179,34 @@ export class SponsorshipRequest implements IEntity<string> {
|
||||
throw new RacingDomainInvariantError(`Cannot withdraw a ${this.status} sponsorship request`);
|
||||
}
|
||||
|
||||
return new SponsorshipRequest({
|
||||
...this,
|
||||
const base: SponsorshipRequestProps = {
|
||||
id: this.id,
|
||||
sponsorId: this.sponsorId,
|
||||
entityType: this.entityType,
|
||||
entityId: this.entityId,
|
||||
tier: this.tier,
|
||||
offeredAmount: this.offeredAmount,
|
||||
status: 'withdrawn',
|
||||
createdAt: this.createdAt,
|
||||
respondedAt: new Date(),
|
||||
});
|
||||
};
|
||||
|
||||
const withRespondedBy =
|
||||
this.respondedBy !== undefined
|
||||
? { ...base, respondedBy: this.respondedBy }
|
||||
: base;
|
||||
|
||||
const withMessage =
|
||||
this.message !== undefined
|
||||
? { ...withRespondedBy, message: this.message }
|
||||
: withRespondedBy;
|
||||
|
||||
const next: SponsorshipRequestProps =
|
||||
this.rejectionReason !== undefined
|
||||
? { ...withMessage, rejectionReason: this.rejectionReason }
|
||||
: withMessage;
|
||||
|
||||
return new SponsorshipRequest(next);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user