Entity
Entity
export type CharacterUniverse = 'marvel' | 'dc';
export type CharacterAlignment = 'hero' | 'villain' | 'anti-hero';
export class Character {
constructor(
public readonly id: string,
public readonly name: string,
public readonly universe: CharacterUniverse,
public readonly alignment: CharacterAlignment,
public readonly createdAt: Date,
public readonly updatedAt: Date,
) {}
}Validated factories
import { Result, Failure } from '@soapjs/soap';
static create(props: CharacterProps): Result<Character> {
if (!props.name?.trim()) {
return Result.withFailure(Failure.fromError(new ValidationError('name is required')));
}
return Result.withSuccess(new Character(/* ...validated fields */));
}Last updated