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:
@@ -92,6 +92,7 @@ class FalukantController {
|
|||||||
if (!result) throw { status: 404, message: 'No family data found' };
|
if (!result) throw { status: 404, message: 'No family data found' };
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
this.setHeir = this._wrapWithUser((userId, req) => this.service.setHeir(userId, req.body.childCharacterId));
|
||||||
this.acceptMarriageProposal = this._wrapWithUser((userId, req) => this.service.acceptMarriageProposal(userId, req.body.proposalId));
|
this.acceptMarriageProposal = this._wrapWithUser((userId, req) => this.service.acceptMarriageProposal(userId, req.body.proposalId));
|
||||||
this.getGifts = this._wrapWithUser((userId) => {
|
this.getGifts = this._wrapWithUser((userId) => {
|
||||||
console.log('🔍 getGifts called with userId:', userId);
|
console.log('🔍 getGifts called with userId:', userId);
|
||||||
|
|||||||
9
backend/migrations/add_is_heir_to_child_relation.sql
Normal file
9
backend/migrations/add_is_heir_to_child_relation.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- Migration: Add is_heir column to child_relation table
|
||||||
|
-- Date: 2025-12-08
|
||||||
|
-- Description: Adds a boolean field to mark a child as the heir
|
||||||
|
|
||||||
|
ALTER TABLE falukant_data.child_relation
|
||||||
|
ADD COLUMN IF NOT EXISTS is_heir BOOLEAN DEFAULT false;
|
||||||
|
|
||||||
|
COMMENT ON COLUMN falukant_data.child_relation.is_heir IS 'Marks whether this child is set as the heir';
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ router.get('/director/:branchId', falukantController.getDirectorForBranch);
|
|||||||
router.get('/directors', falukantController.getAllDirectors);
|
router.get('/directors', falukantController.getAllDirectors);
|
||||||
router.post('/directors', falukantController.updateDirector);
|
router.post('/directors', falukantController.updateDirector);
|
||||||
router.post('/family/acceptmarriageproposal', falukantController.acceptMarriageProposal);
|
router.post('/family/acceptmarriageproposal', falukantController.acceptMarriageProposal);
|
||||||
|
router.post('/family/set-heir', falukantController.setHeir);
|
||||||
router.get('/family/gifts', falukantController.getGifts);
|
router.get('/family/gifts', falukantController.getGifts);
|
||||||
router.get('/family/children', falukantController.getChildren);
|
router.get('/family/children', falukantController.getChildren);
|
||||||
router.post('/family/gift', falukantController.sendGift);
|
router.post('/family/gift', falukantController.sendGift);
|
||||||
|
|||||||
@@ -2391,11 +2391,13 @@ class FalukantService extends BaseService {
|
|||||||
for (const rel of allRels) {
|
for (const rel of allRels) {
|
||||||
const kid = rel.child;
|
const kid = rel.child;
|
||||||
children.push({
|
children.push({
|
||||||
|
childCharacterId: kid.id,
|
||||||
name: kid.definedFirstName?.name || 'Unknown',
|
name: kid.definedFirstName?.name || 'Unknown',
|
||||||
gender: kid.gender,
|
gender: kid.gender,
|
||||||
age: calcAge(kid.birthdate),
|
age: calcAge(kid.birthdate),
|
||||||
hasName: rel.nameSet,
|
hasName: rel.nameSet,
|
||||||
_createdAt: rel.createdAt,
|
isHeir: rel.isHeir || false,
|
||||||
|
_createdAt: rel.createdAt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2426,6 +2428,46 @@ class FalukantService extends BaseService {
|
|||||||
return family;
|
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) {
|
async getPossiblePartners(requestingCharacterId) {
|
||||||
const proposals = await MarriageProposal.findAll({
|
const proposals = await MarriageProposal.findAll({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -405,6 +405,11 @@
|
|||||||
"title": "Kinder",
|
"title": "Kinder",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"age": "Alter",
|
"age": "Alter",
|
||||||
|
"heir": "Erbe",
|
||||||
|
"isHeir": "Erbe",
|
||||||
|
"setAsHeir": "Als Erben festlegen",
|
||||||
|
"heirSetSuccess": "Das Kind wurde erfolgreich als Erbe festgelegt.",
|
||||||
|
"heirSetError": "Fehler beim Festlegen des Erben.",
|
||||||
"actions": "Aktionen",
|
"actions": "Aktionen",
|
||||||
"none": "Keine Kinder vorhanden.",
|
"none": "Keine Kinder vorhanden.",
|
||||||
"detailButton": "Details anzeigen",
|
"detailButton": "Details anzeigen",
|
||||||
|
|||||||
@@ -201,6 +201,23 @@
|
|||||||
"councillor": "Councillor",
|
"councillor": "Councillor",
|
||||||
"assessor": "Assessor"
|
"assessor": "Assessor"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"family": {
|
||||||
|
"children": {
|
||||||
|
"title": "Children",
|
||||||
|
"name": "Name",
|
||||||
|
"age": "Age",
|
||||||
|
"heir": "Heir",
|
||||||
|
"isHeir": "Heir",
|
||||||
|
"setAsHeir": "Set as Heir",
|
||||||
|
"heirSetSuccess": "The child has been successfully set as heir.",
|
||||||
|
"heirSetError": "Error setting heir.",
|
||||||
|
"actions": "Actions",
|
||||||
|
"none": "No children available.",
|
||||||
|
"detailButton": "Show Details",
|
||||||
|
"addChild": "Add Child",
|
||||||
|
"baptism": "Baptize"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +117,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>{{ $t('falukant.family.children.name') }}</th>
|
<th>{{ $t('falukant.family.children.name') }}</th>
|
||||||
<th>{{ $t('falukant.family.children.age') }}</th>
|
<th>{{ $t('falukant.family.children.age') }}</th>
|
||||||
|
<th>{{ $t('falukant.family.children.heir') }}</th>
|
||||||
<th>{{ $t('falukant.family.children.actions') }}</th>
|
<th>{{ $t('falukant.family.children.actions') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -130,6 +131,12 @@
|
|||||||
}}</button>
|
}}</button>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ child.age }}</td>
|
<td>{{ child.age }}</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="child.isHeir" class="heir-badge">{{ $t('falukant.family.children.isHeir') }}</span>
|
||||||
|
<button v-else-if="child.hasName" @click="setAsHeir(child)" class="set-heir-button">
|
||||||
|
{{ $t('falukant.family.children.setAsHeir') }}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button @click="showChildDetails(child)">
|
<button @click="showChildDetails(child)">
|
||||||
{{ $t('falukant.family.children.detailButton') }}
|
{{ $t('falukant.family.children.detailButton') }}
|
||||||
@@ -241,6 +248,23 @@ export default {
|
|||||||
console.log('Show details for child:', child);
|
console.log('Show details for child:', child);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async setAsHeir(child) {
|
||||||
|
if (!child.childCharacterId) {
|
||||||
|
console.error('Child character ID missing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await apiClient.post('/api/falukant/family/set-heir', {
|
||||||
|
childCharacterId: child.childCharacterId
|
||||||
|
});
|
||||||
|
await this.loadFamilyData();
|
||||||
|
this.$root.$refs.messageDialog?.open('tr:falukant.family.children.heirSetSuccess');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error setting heir:', error);
|
||||||
|
this.$root.$refs.errorDialog?.open('tr:falukant.family.children.heirSetError');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
formatCost(value) {
|
formatCost(value) {
|
||||||
return new Intl.NumberFormat(navigator.language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value);
|
return new Intl.NumberFormat(navigator.language, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value);
|
||||||
},
|
},
|
||||||
@@ -457,4 +481,28 @@ h2 {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
transition: width 0.3s ease, background-color 0.3s ease;
|
transition: width 0.3s ease, background-color 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.heir-badge {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 4px 8px;
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.set-heir-button {
|
||||||
|
padding: 4px 8px;
|
||||||
|
background-color: #2196F3;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.set-heir-button:hover {
|
||||||
|
background-color: #1976D2;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user