feat: expose health and demo character APIs

This commit is contained in:
Bastian Wagner
2026-08-18 20:00:40 +02:00
parent 0615bb1841
commit e9b111daf8
14 changed files with 208 additions and 51 deletions

View File

@@ -0,0 +1,39 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { DEMO_CHARACTER_ID } from '../demo/demo-character.constants';
import { Character } from './entities/character.entity';
@Injectable()
export class CharactersService {
constructor(
@InjectRepository(Character)
private readonly characters: Repository<Character>,
) {}
async getDemoCharacter() {
const character = await this.characters.findOne({
where: { id: DEMO_CHARACTER_ID },
relations: { currentLocation: true },
});
if (!character) {
throw new NotFoundException('Demo character has not been seeded');
}
return {
id: character.id,
name: character.name,
level: character.level,
experience: character.experience,
currentHp: character.currentHp,
maxHp: character.baseHp,
attack: character.baseAttack,
currentLocation: {
id: character.currentLocation.id,
key: character.currentLocation.key,
name: character.currentLocation.name,
},
};
}
}