Refactor getCumulativeTaxPercentWithExemptions function in falukantService.js to filter political offices by userId through the FalukantCharacter model. Update query structure to enhance clarity and ensure accurate data retrieval for regional tax calculations.

This commit is contained in:
Torsten Schulz (local)
2025-12-20 10:48:56 +01:00
parent a0aa678e7d
commit 66e6fab663

View File

@@ -147,9 +147,31 @@ async function calcRegionalSellPrice(product, knowledgeFactor, regionId, worthPe
async function getCumulativeTaxPercentWithExemptions(userId, regionId) {
if (!regionId) return 0;
// fetch user's political offices (active) and their region types
// PoliticalOffice hat keine userId Spalte, daher müssen wir über FalukantCharacter filtern
const offices = await PoliticalOffice.findAll({
include: [
{
model: FalukantCharacter,
as: 'holder',
where: { userId },
include: [{ model: PoliticalOfficeType, as: 'type', attributes: ['name'] }, { model: RegionData, as: 'region', include: [{ model: RegionType, as: 'regionType', attributes: ['labelTr'] }] }]
required: true,
attributes: []
},
{
model: PoliticalOfficeType,
as: 'type',
attributes: ['name']
},
{
model: RegionData,
as: 'region',
include: [{
model: RegionType,
as: 'regionType',
attributes: ['labelTr']
}]
}
]
});
// build set of exempt region type labels from user's offices