feat(family): enhance family view and character pregnancy handling
All checks were successful
Deploy to production / deploy (push) Successful in 2m48s
All checks were successful
Deploy to production / deploy (push) Successful in 2m48s
- Updated the FalukantCharacter model to include a default scope that excludes pregnancy-related fields for compatibility with older databases. - Implemented a new method in FalukantService to conditionally retrieve pregnancy information based on database schema. - Enhanced the FamilyView component to display a summary navigation for family relationships, including partners, children, and lovers. - Updated internationalization files to include new translations for family-related terms and summaries.
This commit is contained in:
@@ -61,7 +61,12 @@ FalukantCharacter.init(
|
||||
tableName: 'character',
|
||||
schema: 'falukant_data',
|
||||
timestamps: true,
|
||||
underscored: true}
|
||||
underscored: true,
|
||||
// Spalten erst nach Migration 20260330000000; ohne Exclude würde SELECT/INSERT auf alten DBs fehlschlagen
|
||||
defaultScope: {
|
||||
attributes: { exclude: ['pregnancyDueAt', 'pregnancyFatherCharacterId'] },
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export default FalukantCharacter;
|
||||
|
||||
@@ -3320,11 +3320,31 @@ class FalukantService extends BaseService {
|
||||
return { result: 'ok' };
|
||||
}
|
||||
|
||||
/** Liest Schwangerschaft nur wenn DB-Spalten existieren (nach Migration). */
|
||||
async _getCharacterPregnancyOptional(characterId) {
|
||||
try {
|
||||
const rows = await sequelize.query(
|
||||
`SELECT pregnancy_due_at, pregnancy_father_character_id
|
||||
FROM falukant_data."character" WHERE id = :id`,
|
||||
{ replacements: { id: characterId }, type: Sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
const row = rows[0];
|
||||
if (!row?.pregnancy_due_at) return null;
|
||||
return {
|
||||
dueAt: row.pregnancy_due_at,
|
||||
fatherCharacterId: row.pregnancy_father_character_id,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getFamily(hashedUserId) {
|
||||
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');
|
||||
const pregnancy = await this._getCharacterPregnancyOptional(character.id);
|
||||
// Load relationships without includes to avoid EagerLoadingError
|
||||
const relRows = await Relationship.findAll({
|
||||
where: { character1Id: character.id },
|
||||
@@ -3519,12 +3539,7 @@ class FalukantService extends BaseService {
|
||||
children: children.map(({ _createdAt, ...rest }) => rest),
|
||||
possiblePartners: [],
|
||||
possibleLovers: [],
|
||||
pregnancy: character.pregnancyDueAt
|
||||
? {
|
||||
dueAt: character.pregnancyDueAt,
|
||||
fatherCharacterId: character.pregnancyFatherCharacterId,
|
||||
}
|
||||
: null,
|
||||
pregnancy,
|
||||
};
|
||||
const ownAge = calcAge(character.birthdate);
|
||||
if (ownAge >= 12) {
|
||||
|
||||
Reference in New Issue
Block a user