Add heir management functionality in Falukant module
- Implemented setHeir method in FalukantService to designate a child as heir, including validation checks for user and child relationships. - Updated FalukantController to expose the setHeir endpoint, allowing users to set heirs via the API. - Enhanced FalukantRouter with a new route for setting heirs. - Modified FamilyView component to include UI elements for setting heirs, with success and error feedback. - Updated localization files in both German and English to include new translations related to heir management, improving user experience.
This commit is contained in:
@@ -2391,11 +2391,13 @@ class FalukantService extends BaseService {
|
||||
for (const rel of allRels) {
|
||||
const kid = rel.child;
|
||||
children.push({
|
||||
childCharacterId: kid.id,
|
||||
name: kid.definedFirstName?.name || 'Unknown',
|
||||
gender: kid.gender,
|
||||
age: calcAge(kid.birthdate),
|
||||
hasName: rel.nameSet,
|
||||
_createdAt: rel.createdAt,
|
||||
hasName: rel.nameSet,
|
||||
isHeir: rel.isHeir || false,
|
||||
_createdAt: rel.createdAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2426,6 +2428,46 @@ class FalukantService extends BaseService {
|
||||
return family;
|
||||
}
|
||||
|
||||
async setHeir(hashedUserId, childCharacterId) {
|
||||
const user = await this.getFalukantUserByHashedId(hashedUserId);
|
||||
if (!user) throw new Error('User not found');
|
||||
const character = await FalukantCharacter.findOne({ where: { userId: user.id } });
|
||||
if (!character) throw new Error('Character not found for this user');
|
||||
|
||||
// Prüfe, ob das Kind wirklich ein Kind des aktuellen Charakters ist
|
||||
const childRelation = await ChildRelation.findOne({
|
||||
where: {
|
||||
childCharacterId: childCharacterId,
|
||||
[Op.or]: [
|
||||
{ fatherCharacterId: character.id },
|
||||
{ motherCharacterId: character.id }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
if (!childRelation) {
|
||||
throw new Error('Child not found or not your child');
|
||||
}
|
||||
|
||||
// Setze alle anderen Kinder des gleichen Elternteils auf isHeir = false
|
||||
await ChildRelation.update(
|
||||
{ isHeir: false },
|
||||
{
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ fatherCharacterId: character.id },
|
||||
{ motherCharacterId: character.id }
|
||||
]
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Setze das ausgewählte Kind als Erben
|
||||
await childRelation.update({ isHeir: true });
|
||||
|
||||
return { success: true, childCharacterId };
|
||||
}
|
||||
|
||||
async getPossiblePartners(requestingCharacterId) {
|
||||
const proposals = await MarriageProposal.findAll({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user