Implement the 002-add-combatant feature that adds the possibility to add new combatants to an encounter
This commit is contained in:
24
packages/application/src/add-combatant-use-case.ts
Normal file
24
packages/application/src/add-combatant-use-case.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
addCombatant,
|
||||
type CombatantId,
|
||||
type DomainError,
|
||||
type DomainEvent,
|
||||
isDomainError,
|
||||
} from "@initiative/domain";
|
||||
import type { EncounterStore } from "./ports.js";
|
||||
|
||||
export function addCombatantUseCase(
|
||||
store: EncounterStore,
|
||||
id: CombatantId,
|
||||
name: string,
|
||||
): DomainEvent[] | DomainError {
|
||||
const encounter = store.get();
|
||||
const result = addCombatant(encounter, id, name);
|
||||
|
||||
if (isDomainError(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
store.save(result.encounter);
|
||||
return result.events;
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export { addCombatantUseCase } from "./add-combatant-use-case.js";
|
||||
export { advanceTurnUseCase } from "./advance-turn-use-case.js";
|
||||
export type { EncounterStore } from "./ports.js";
|
||||
|
||||
Reference in New Issue
Block a user