refactor
This commit is contained in:
@@ -1,27 +1,23 @@
|
||||
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
||||
import type { IEntity } from '@core/shared/domain';
|
||||
|
||||
export class Game implements IEntity<string> {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
import { GameId } from './GameId';
|
||||
import { GameName } from './GameName';
|
||||
|
||||
private constructor(props: { id: string; name: string }) {
|
||||
export class Game implements IEntity<GameId> {
|
||||
readonly id: GameId;
|
||||
readonly name: GameName;
|
||||
|
||||
private constructor(props: { id: GameId; name: GameName }) {
|
||||
this.id = props.id;
|
||||
this.name = props.name;
|
||||
}
|
||||
|
||||
static create(props: { id: string; name: string }): Game {
|
||||
if (!props.id || props.id.trim().length === 0) {
|
||||
throw new RacingDomainValidationError('Game ID is required');
|
||||
}
|
||||
|
||||
if (!props.name || props.name.trim().length === 0) {
|
||||
throw new RacingDomainValidationError('Game name is required');
|
||||
}
|
||||
const id = GameId.create(props.id);
|
||||
const name = GameName.create(props.name);
|
||||
|
||||
return new Game({
|
||||
id: props.id,
|
||||
name: props.name,
|
||||
id,
|
||||
name,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user