feat(Director): add autoAdjustIncome feature and enhance director data handling
All checks were successful
Deploy to production / deploy (push) Successful in 1m54s
All checks were successful
Deploy to production / deploy (push) Successful in 1m54s
- Introduced a new boolean field `autoAdjustIncome` in the Director model to manage income adjustments automatically. - Updated the FalukantService to include `autoAdjustIncome` in director data responses and settings management. - Enhanced the DirectorInfo component to allow users to toggle the `autoAdjustIncome` setting. - Updated internationalization files to include translations for the new feature across multiple languages.
This commit is contained in:
@@ -33,6 +33,10 @@ Director.init({
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true},
|
||||
autoAdjustIncome: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false},
|
||||
lastSalaryPayout: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
|
||||
@@ -3328,7 +3328,7 @@ class FalukantService extends BaseService {
|
||||
{
|
||||
model: RegionData,
|
||||
as: 'region',
|
||||
attributes: ['name']
|
||||
attributes: ['id', 'name']
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3351,6 +3351,7 @@ class FalukantService extends BaseService {
|
||||
return {
|
||||
director: {
|
||||
id: director.id,
|
||||
directorCharacterId: director.directorCharacterId,
|
||||
character: {
|
||||
name: `${director.character.definedFirstName.name} ${director.character.definedLastName.name}`,
|
||||
title: director.character.nobleTitle.labelTr,
|
||||
@@ -3366,6 +3367,8 @@ class FalukantService extends BaseService {
|
||||
mayProduce: director.mayProduce,
|
||||
maySell: director.maySell,
|
||||
mayStartTransport: director.mayStartTransport,
|
||||
autoAdjustIncome: director.autoAdjustIncome,
|
||||
regionId: director.character.region?.id || director.character.regionId || null,
|
||||
region: director.character.region?.name || null,
|
||||
wishedIncome,
|
||||
},
|
||||
@@ -3420,7 +3423,7 @@ class FalukantService extends BaseService {
|
||||
]
|
||||
},
|
||||
],
|
||||
attributes: ['id', 'satisfaction', 'income'],
|
||||
attributes: ['id', 'satisfaction', 'income', 'autoAdjustIncome'],
|
||||
});
|
||||
return directors
|
||||
.filter(director => director.character != null)
|
||||
@@ -3436,10 +3439,13 @@ class FalukantService extends BaseService {
|
||||
);
|
||||
return {
|
||||
id: director.id,
|
||||
directorCharacterId: char.id,
|
||||
satisfaction: director.satisfaction,
|
||||
character: char,
|
||||
age: calcAge(char.birthdate),
|
||||
income: director.income,
|
||||
autoAdjustIncome: director.autoAdjustIncome,
|
||||
regionId: char.region?.id ?? null,
|
||||
region: char.region?.name ?? '',
|
||||
wishedIncome,
|
||||
};
|
||||
@@ -3488,8 +3494,18 @@ class FalukantService extends BaseService {
|
||||
if (!director) {
|
||||
return null;
|
||||
}
|
||||
const allowedKeys = new Set([
|
||||
'mayProduce',
|
||||
'maySell',
|
||||
'mayStartTransport',
|
||||
'mayRepairVehicles',
|
||||
'autoAdjustIncome',
|
||||
]);
|
||||
if (!allowedKeys.has(settingKey)) {
|
||||
throw new Error('Invalid setting key');
|
||||
}
|
||||
const updateData = {};
|
||||
updateData[settingKey] = value || false;
|
||||
updateData[settingKey] = !!value;
|
||||
|
||||
await Director.update(updateData, {
|
||||
where: {
|
||||
@@ -8905,15 +8921,18 @@ async function enrichNotificationsWithCharacterNames(notifications) {
|
||||
where: { id: { [Op.in]: ids } },
|
||||
include: [
|
||||
{ model: FalukantPredefineFirstname, as: 'definedFirstName', attributes: ['name'] },
|
||||
{ model: FalukantPredefineLastname, as: 'definedLastName', attributes: ['name'] }
|
||||
{ model: FalukantPredefineLastname, as: 'definedLastName', attributes: ['name'] },
|
||||
{ model: TitleOfNobility, as: 'nobleTitle', attributes: ['labelTr'] },
|
||||
],
|
||||
attributes: ['id']
|
||||
attributes: ['id', 'gender']
|
||||
});
|
||||
|
||||
for (const c of characters) {
|
||||
const title = String(c.nobleTitle?.labelTr || '').trim();
|
||||
const first = c.definedFirstName?.name || '';
|
||||
const last = c.definedLastName?.name || '';
|
||||
const display = `${first} ${last}`.trim() || null;
|
||||
const baseName = `${first} ${last}`.trim();
|
||||
const display = [title, baseName].filter(Boolean).join(' ').trim() || null;
|
||||
nameMap.set(Number(c.id), display || `#${c.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
15
backend/sql/add_director_auto_adjust_income.sql
Normal file
15
backend/sql/add_director_auto_adjust_income.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- Adds opt-in flag for automatic director salary adjustment (daemon-controlled)
|
||||
-- Default is OFF for all existing and future directors.
|
||||
|
||||
ALTER TABLE falukant_data.director
|
||||
ADD COLUMN IF NOT EXISTS auto_adjust_income boolean;
|
||||
|
||||
UPDATE falukant_data.director
|
||||
SET auto_adjust_income = false
|
||||
WHERE auto_adjust_income IS NULL;
|
||||
|
||||
ALTER TABLE falukant_data.director
|
||||
ALTER COLUMN auto_adjust_income SET DEFAULT false;
|
||||
|
||||
ALTER TABLE falukant_data.director
|
||||
ALTER COLUMN auto_adjust_income SET NOT NULL;
|
||||
Reference in New Issue
Block a user