25 lines
504 B
TypeScript
25 lines
504 B
TypeScript
import {
|
|
type CombatantId,
|
|
type DomainError,
|
|
type DomainEvent,
|
|
editCombatant,
|
|
isDomainError,
|
|
} from "@initiative/domain";
|
|
import type { EncounterStore } from "./ports.js";
|
|
|
|
export function editCombatantUseCase(
|
|
store: EncounterStore,
|
|
id: CombatantId,
|
|
newName: string,
|
|
): DomainEvent[] | DomainError {
|
|
const encounter = store.get();
|
|
const result = editCombatant(encounter, id, newName);
|
|
|
|
if (isDomainError(result)) {
|
|
return result;
|
|
}
|
|
|
|
store.save(result.encounter);
|
|
return result.events;
|
|
}
|