fix(falukant): validate office term length and adjust term end calculation
All checks were successful
Deploy to production / deploy (push) Successful in 2m51s

- Added validation for office term length to ensure it is a positive finite number, throwing an error for invalid values.
- Updated the calculation of the term end date to use the term length in days instead of years, aligning with the expected data format.
This commit is contained in:
Torsten Schulz (local)
2026-04-10 16:08:50 +02:00
parent c6419c6c34
commit 60ef98283f
2 changed files with 11 additions and 4 deletions

View File

@@ -457,8 +457,14 @@ class FalukantPoliticalPowersService {
}
const start = new Date();
const termDays = Number(officeType.termLength);
if (!Number.isFinite(termDays) || termDays <= 0) {
const err = new Error('invalid_office_term_length');
err.status = 500;
throw err;
}
const end = new Date(start);
end.setFullYear(end.getFullYear() + (officeType.termLength || 4));
end.setDate(end.getDate() + termDays);
let newOffice;
await sequelize.transaction(async (t) => {