From 66e6fab663272ca95ab481182d41a1727f4b9df4 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 20 Dec 2025 10:48:56 +0100 Subject: [PATCH] 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. --- backend/services/falukantService.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/services/falukantService.js b/backend/services/falukantService.js index 0e6c6d3..eb8ad10 100644 --- a/backend/services/falukantService.js +++ b/backend/services/falukantService.js @@ -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({ - where: { userId }, - include: [{ model: PoliticalOfficeType, as: 'type', attributes: ['name'] }, { model: RegionData, as: 'region', include: [{ model: RegionType, as: 'regionType', attributes: ['labelTr'] }] }] + include: [ + { + model: FalukantCharacter, + as: 'holder', + where: { userId }, + 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