Bereinigen und Entfernen von nicht mehr benötigten TinyMCE-Dateien und -Plugins; Aktualisierung der Internationalisierung für Deutsch und Englisch in den Falukant- und Navigationsmodulen; Verbesserung der Statusleiste und Router-Implementierung.
This commit is contained in:
@@ -298,10 +298,79 @@ class FalukantService extends BaseService {
|
||||
]
|
||||
},
|
||||
],
|
||||
attributes: ['money']
|
||||
attributes: ['id', 'money']
|
||||
});
|
||||
if (!falukantUser) throw new Error('User not found');
|
||||
if (falukantUser.character?.birthdate) falukantUser.character.setDataValue('age', calcAge(falukantUser.character.birthdate));
|
||||
|
||||
// Aggregate status additions: children counts and unread notifications
|
||||
try {
|
||||
const bm = (step, payload = {}) => {
|
||||
try { console.log(`[BLOCKMARKER][falukant.getInfo] ${step}`, payload); } catch (_) { /* ignore */ }
|
||||
};
|
||||
bm('aggregate.start', { userId: user.id, falukantUserId: falukantUser.id });
|
||||
// Determine all character IDs belonging to the user
|
||||
if (!falukantUser.id) {
|
||||
bm('aggregate.noFalukantUserId');
|
||||
throw new Error('Missing falukantUser.id in getInfo aggregation');
|
||||
}
|
||||
const userCharacterIdsRows = await FalukantCharacter.findAll({
|
||||
attributes: ['id'],
|
||||
where: { userId: falukantUser.id },
|
||||
raw: true
|
||||
});
|
||||
const userCharacterIds = userCharacterIdsRows.map(r => r.id);
|
||||
bm('aggregate.userCharacters', { count: userCharacterIds.length, ids: userCharacterIds.slice(0, 5) });
|
||||
|
||||
// Count distinct children for any of the user's characters (as father or mother)
|
||||
let childrenCount = 0;
|
||||
let unbaptisedChildrenCount = 0;
|
||||
if (userCharacterIds.length > 0) {
|
||||
const childRels = await ChildRelation.findAll({
|
||||
attributes: ['childCharacterId'],
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ fatherCharacterId: { [Op.in]: userCharacterIds } },
|
||||
{ motherCharacterId: { [Op.in]: userCharacterIds } },
|
||||
]
|
||||
},
|
||||
raw: true
|
||||
});
|
||||
const distinctChildIds = new Set(childRels.map(r => r.childCharacterId));
|
||||
childrenCount = distinctChildIds.size;
|
||||
bm('aggregate.children', { relations: childRels.length, distinct: childrenCount, sample: Array.from(distinctChildIds).slice(0, 5) });
|
||||
|
||||
const unbaptised = await ChildRelation.findAll({
|
||||
attributes: ['childCharacterId'],
|
||||
where: {
|
||||
nameSet: false,
|
||||
[Op.or]: [
|
||||
{ fatherCharacterId: { [Op.in]: userCharacterIds } },
|
||||
{ motherCharacterId: { [Op.in]: userCharacterIds } },
|
||||
]
|
||||
},
|
||||
raw: true
|
||||
});
|
||||
const distinctUnbaptisedIds = new Set(unbaptised.map(r => r.childCharacterId));
|
||||
unbaptisedChildrenCount = distinctUnbaptisedIds.size;
|
||||
bm('aggregate.unbaptised', { relations: unbaptised.length, distinct: unbaptisedChildrenCount, sample: Array.from(distinctUnbaptisedIds).slice(0, 5) });
|
||||
}
|
||||
|
||||
// Unread notifications count
|
||||
const unreadNotifications = await Notification.count({ where: { userId: falukantUser.id, shown: false } });
|
||||
bm('aggregate.unread', { unreadNotifications });
|
||||
|
||||
falukantUser.setDataValue('childrenCount', childrenCount);
|
||||
falukantUser.setDataValue('unbaptisedChildrenCount', unbaptisedChildrenCount);
|
||||
falukantUser.setDataValue('unreadNotifications', unreadNotifications);
|
||||
bm('aggregate.done', { childrenCount, unbaptisedChildrenCount });
|
||||
} catch (e) {
|
||||
console.error('Error aggregating status info:', e);
|
||||
falukantUser.setDataValue('childrenCount', 0);
|
||||
falukantUser.setDataValue('unbaptisedChildrenCount', 0);
|
||||
falukantUser.setDataValue('unreadNotifications', 0);
|
||||
}
|
||||
|
||||
return falukantUser;
|
||||
}
|
||||
|
||||
@@ -898,12 +967,9 @@ class FalukantService extends BaseService {
|
||||
await this.deleteExpiredProposals();
|
||||
const existingProposals = await this.fetchProposals(falukantUserId, regionId);
|
||||
if (existingProposals.length > 0) {
|
||||
console.log('Existing proposals:', existingProposals);
|
||||
return this.formatProposals(existingProposals);
|
||||
}
|
||||
console.log('No existing proposals, generating new ones');
|
||||
await this.generateProposals(falukantUserId, regionId);
|
||||
console.log('Fetch new proposals');
|
||||
const newProposals = await this.fetchProposals(falukantUserId, regionId);
|
||||
return this.formatProposals(newProposals);
|
||||
}
|
||||
@@ -1320,7 +1386,7 @@ class FalukantService extends BaseService {
|
||||
}
|
||||
]
|
||||
});
|
||||
const children = [];
|
||||
const children = [];
|
||||
for (const parentChar of charsWithChildren) {
|
||||
const allRels = [
|
||||
...(parentChar.childrenFather || []),
|
||||
@@ -1332,16 +1398,19 @@ class FalukantService extends BaseService {
|
||||
name: kid.definedFirstName?.name || 'Unknown',
|
||||
gender: kid.gender,
|
||||
age: calcAge(kid.birthdate),
|
||||
hasName: rel.nameSet,
|
||||
hasName: rel.nameSet,
|
||||
_createdAt: rel.createdAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
// Sort children globally by relation createdAt ascending (older first)
|
||||
children.sort((a, b) => new Date(a._createdAt) - new Date(b._createdAt));
|
||||
const inProgress = ['wooing', 'engaged', 'married'];
|
||||
const family = {
|
||||
relationships: relationships.filter(r => inProgress.includes(r.relationshipType)),
|
||||
lovers: relationships.filter(r => r.relationshipType === 'lover'),
|
||||
deathPartners: relationships.filter(r => r.relationshipType === 'widowed'),
|
||||
children,
|
||||
children: children.map(({ _createdAt, ...rest }) => rest),
|
||||
possiblePartners: []
|
||||
};
|
||||
const ownAge = calcAge(character.birthdate);
|
||||
@@ -1983,62 +2052,66 @@ class FalukantService extends BaseService {
|
||||
}
|
||||
|
||||
async baptise(hashedUserId, childId, firstName) {
|
||||
const falukantUser = await getFalukantUserOrFail(hashedUserId);
|
||||
const parentCharacter = await FalukantCharacter.findOne({
|
||||
where: {
|
||||
userId: falukantUser.id,
|
||||
},
|
||||
});
|
||||
if (!parentCharacter) {
|
||||
throw new Error('Parent character not found');
|
||||
}
|
||||
const child = await FalukantCharacter.findOne({
|
||||
where: {
|
||||
id: childId,
|
||||
},
|
||||
});
|
||||
if (!child) {
|
||||
throw new Error('Child not found');
|
||||
}
|
||||
const childRelation = await ChildRelation.findOne({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{
|
||||
fatherCharacterId: parentCharacter.id,
|
||||
childCharacterId: child.id,
|
||||
},
|
||||
{
|
||||
motherCharacterId: parentCharacter.id,
|
||||
childCharacterId: child.id,
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
if (!childRelation) {
|
||||
throw new Error('Child relation not found');
|
||||
}
|
||||
await childRelation.update({
|
||||
nameSet: true,
|
||||
});
|
||||
let firstNameObject = FalukantPredefineFirstname.findOne({
|
||||
where: {
|
||||
name: firstName,
|
||||
gender: child.gender,
|
||||
},
|
||||
});
|
||||
if (!firstNameObject) {
|
||||
firstNameObject = await FalukantPredefineFirstname.create({
|
||||
name: firstName,
|
||||
gender: child.gender,
|
||||
try {
|
||||
const falukantUser = await getFalukantUserOrFail(hashedUserId);
|
||||
const parentCharacter = await FalukantCharacter.findOne({
|
||||
where: {
|
||||
userId: falukantUser.id,
|
||||
},
|
||||
});
|
||||
if (!parentCharacter) {
|
||||
throw new Error('Parent character not found');
|
||||
}
|
||||
const child = await FalukantCharacter.findOne({
|
||||
where: {
|
||||
id: childId,
|
||||
},
|
||||
});
|
||||
if (!child) {
|
||||
throw new Error('Child not found');
|
||||
}
|
||||
const childRelation = await ChildRelation.findOne({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{
|
||||
fatherCharacterId: parentCharacter.id,
|
||||
childCharacterId: child.id,
|
||||
},
|
||||
{
|
||||
motherCharacterId: parentCharacter.id,
|
||||
childCharacterId: child.id,
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
if (!childRelation) {
|
||||
throw new Error('Child relation not found');
|
||||
}
|
||||
await childRelation.update({
|
||||
nameSet: true,
|
||||
});
|
||||
let firstNameObject = await FalukantPredefineFirstname.findOne({
|
||||
where: {
|
||||
name: firstName,
|
||||
gender: child.gender,
|
||||
},
|
||||
});
|
||||
if (!firstNameObject) {
|
||||
firstNameObject = await FalukantPredefineFirstname.create({
|
||||
name: firstName,
|
||||
gender: child.gender,
|
||||
});
|
||||
}
|
||||
await child.update({
|
||||
firstName: firstNameObject.id,
|
||||
});
|
||||
updateFalukantUserMoney(falukantUser.id, -50, 'Baptism', falukantUser.id);
|
||||
// Trigger status bar refresh for the user after baptism
|
||||
notifyUser(hashedUserId, 'falukantUpdateStatus', {});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
await child.update({
|
||||
firstName: firstNameObject.id,
|
||||
});
|
||||
updateFalukantUserMoney(falukantUser.id, -50, 'Baptism', falukantUser.id);
|
||||
return { success: true };
|
||||
} catch(error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
async getEducation(hashedUserId) {
|
||||
@@ -2795,7 +2868,29 @@ class FalukantService extends BaseService {
|
||||
where: { userId: user.id, shown: false },
|
||||
order: [['createdAt', 'DESC']]
|
||||
});
|
||||
return user.notifications;
|
||||
return notifications;
|
||||
}
|
||||
|
||||
async getAllNotifications(hashedUserId, page = 1, size = 10) {
|
||||
const user = await getFalukantUserOrFail(hashedUserId);
|
||||
const limit = Math.max(1, Math.min(Number(size) || 10, 100));
|
||||
const offset = Math.max(0, ((Number(page) || 1) - 1) * limit);
|
||||
const { rows, count } = await Notification.findAndCountAll({
|
||||
where: { userId: user.id },
|
||||
order: [['createdAt', 'DESC']],
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
return { items: rows, total: count, page: Number(page) || 1, size: limit };
|
||||
}
|
||||
|
||||
async markNotificationsShown(hashedUserId) {
|
||||
const user = await getFalukantUserOrFail(hashedUserId);
|
||||
const [count] = await Notification.update(
|
||||
{ shown: true },
|
||||
{ where: { userId: user.id, shown: false } }
|
||||
);
|
||||
return { updated: count };
|
||||
}
|
||||
|
||||
async getPoliticalOfficeHolders(hashedUserId) {
|
||||
|
||||
Reference in New Issue
Block a user