wip
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* Domain Entity: DriverLivery
|
||||
*/
|
||||
|
||||
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
|
||||
*
|
||||
* Represents a driver's custom livery for a specific car.
|
||||
* Includes user-placed decals and league-specific overrides.
|
||||
@@ -70,23 +73,23 @@ export class DriverLivery {
|
||||
|
||||
private static validate(props: Omit<DriverLiveryProps, 'createdAt' | 'userDecals' | 'leagueOverrides'>): void {
|
||||
if (!props.id || props.id.trim().length === 0) {
|
||||
throw new Error('DriverLivery ID is required');
|
||||
throw new RacingDomainValidationError('DriverLivery ID is required');
|
||||
}
|
||||
|
||||
if (!props.driverId || props.driverId.trim().length === 0) {
|
||||
throw new Error('DriverLivery driverId is required');
|
||||
throw new RacingDomainValidationError('DriverLivery driverId is required');
|
||||
}
|
||||
|
||||
if (!props.gameId || props.gameId.trim().length === 0) {
|
||||
throw new Error('DriverLivery gameId is required');
|
||||
throw new RacingDomainValidationError('DriverLivery gameId is required');
|
||||
}
|
||||
|
||||
if (!props.carId || props.carId.trim().length === 0) {
|
||||
throw new Error('DriverLivery carId is required');
|
||||
throw new RacingDomainValidationError('DriverLivery carId is required');
|
||||
}
|
||||
|
||||
if (!props.uploadedImageUrl || props.uploadedImageUrl.trim().length === 0) {
|
||||
throw new Error('DriverLivery uploadedImageUrl is required');
|
||||
throw new RacingDomainValidationError('DriverLivery uploadedImageUrl is required');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +98,7 @@ export class DriverLivery {
|
||||
*/
|
||||
addDecal(decal: LiveryDecal): DriverLivery {
|
||||
if (decal.type !== 'user') {
|
||||
throw new Error('Only user decals can be added to driver livery');
|
||||
throw new RacingDomainInvariantError('Only user decals can be added to driver livery');
|
||||
}
|
||||
|
||||
return new DriverLivery({
|
||||
@@ -112,7 +115,7 @@ export class DriverLivery {
|
||||
const updatedDecals = this.userDecals.filter(d => d.id !== decalId);
|
||||
|
||||
if (updatedDecals.length === this.userDecals.length) {
|
||||
throw new Error('Decal not found in livery');
|
||||
throw new RacingDomainValidationError('Decal not found in livery');
|
||||
}
|
||||
|
||||
return new DriverLivery({
|
||||
@@ -129,7 +132,7 @@ export class DriverLivery {
|
||||
const index = this.userDecals.findIndex(d => d.id === decalId);
|
||||
|
||||
if (index === -1) {
|
||||
throw new Error('Decal not found in livery');
|
||||
throw new RacingDomainError('Decal not found in livery');
|
||||
}
|
||||
|
||||
const updatedDecals = [...this.userDecals];
|
||||
|
||||
Reference in New Issue
Block a user