diff --git a/backend/controllers/falukantController.js b/backend/controllers/falukantController.js index 0572543..a07f01d 100644 --- a/backend/controllers/falukantController.js +++ b/backend/controllers/falukantController.js @@ -92,6 +92,7 @@ class FalukantController { if (!result) throw { status: 404, message: 'No family data found' }; 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.getGifts = this._wrapWithUser((userId) => { console.log('🔍 getGifts called with userId:', userId); diff --git a/backend/migrations/add_is_heir_to_child_relation.sql b/backend/migrations/add_is_heir_to_child_relation.sql new file mode 100644 index 0000000..5aa840f --- /dev/null +++ b/backend/migrations/add_is_heir_to_child_relation.sql @@ -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'; + diff --git a/backend/routers/falukantRouter.js b/backend/routers/falukantRouter.js index 9f998b9..802b535 100644 --- a/backend/routers/falukantRouter.js +++ b/backend/routers/falukantRouter.js @@ -38,6 +38,7 @@ router.get('/director/:branchId', falukantController.getDirectorForBranch); router.get('/directors', falukantController.getAllDirectors); router.post('/directors', falukantController.updateDirector); router.post('/family/acceptmarriageproposal', falukantController.acceptMarriageProposal); +router.post('/family/set-heir', falukantController.setHeir); router.get('/family/gifts', falukantController.getGifts); router.get('/family/children', falukantController.getChildren); router.post('/family/gift', falukantController.sendGift); diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index e685032..ba31ce2 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -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: { diff --git a/frontend/src/i18n/locales/de/falukant.json b/frontend/src/i18n/locales/de/falukant.json index 8666698..7b95168 100644 --- a/frontend/src/i18n/locales/de/falukant.json +++ b/frontend/src/i18n/locales/de/falukant.json @@ -405,6 +405,11 @@ "title": "Kinder", "name": "Name", "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", "none": "Keine Kinder vorhanden.", "detailButton": "Details anzeigen", diff --git a/frontend/src/i18n/locales/en/falukant.json b/frontend/src/i18n/locales/en/falukant.json index b83bd34..93eb587 100644 --- a/frontend/src/i18n/locales/en/falukant.json +++ b/frontend/src/i18n/locales/en/falukant.json @@ -201,6 +201,23 @@ "councillor": "Councillor", "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" + } } } } \ No newline at end of file diff --git a/frontend/src/views/falukant/FamilyView.vue b/frontend/src/views/falukant/FamilyView.vue index 121ab3a..13d2d45 100644 --- a/frontend/src/views/falukant/FamilyView.vue +++ b/frontend/src/views/falukant/FamilyView.vue @@ -117,6 +117,7 @@ {{ $t('falukant.family.children.name') }} {{ $t('falukant.family.children.age') }} + {{ $t('falukant.family.children.heir') }} {{ $t('falukant.family.children.actions') }} @@ -130,6 +131,12 @@ }} {{ child.age }} + + {{ $t('falukant.family.children.isHeir') }} + +