This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -1,5 +1,8 @@
/**
* Domain Entity: LiveryTemplate
*/
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
*
* Represents an admin-defined livery template for a specific car.
* Contains base image and sponsor decal placements.
@@ -54,23 +57,23 @@ export class LiveryTemplate {
private static validate(props: Omit<LiveryTemplateProps, 'createdAt' | 'adminDecals'>): void {
if (!props.id || props.id.trim().length === 0) {
throw new Error('LiveryTemplate ID is required');
throw new RacingDomainValidationError('LiveryTemplate ID is required');
}
if (!props.leagueId || props.leagueId.trim().length === 0) {
throw new Error('LiveryTemplate leagueId is required');
throw new RacingDomainValidationError('LiveryTemplate leagueId is required');
}
if (!props.seasonId || props.seasonId.trim().length === 0) {
throw new Error('LiveryTemplate seasonId is required');
throw new RacingDomainValidationError('LiveryTemplate seasonId is required');
}
if (!props.carId || props.carId.trim().length === 0) {
throw new Error('LiveryTemplate carId is required');
throw new RacingDomainValidationError('LiveryTemplate carId is required');
}
if (!props.baseImageUrl || props.baseImageUrl.trim().length === 0) {
throw new Error('LiveryTemplate baseImageUrl is required');
throw new RacingDomainValidationError('LiveryTemplate baseImageUrl is required');
}
}
@@ -79,7 +82,7 @@ export class LiveryTemplate {
*/
addDecal(decal: LiveryDecal): LiveryTemplate {
if (decal.type !== 'sponsor') {
throw new Error('Only sponsor decals can be added to admin template');
throw new RacingDomainInvariantError('Only sponsor decals can be added to admin template');
}
return new LiveryTemplate({
@@ -96,7 +99,7 @@ export class LiveryTemplate {
const updatedDecals = this.adminDecals.filter(d => d.id !== decalId);
if (updatedDecals.length === this.adminDecals.length) {
throw new Error('Decal not found in template');
throw new RacingDomainValidationError('Decal not found in template');
}
return new LiveryTemplate({
@@ -113,7 +116,7 @@ export class LiveryTemplate {
const index = this.adminDecals.findIndex(d => d.id === decalId);
if (index === -1) {
throw new Error('Decal not found in template');
throw new RacingDomainError('Decal not found in template');
}
const updatedDecals = [...this.adminDecals];