Skip to content

Commit

Permalink
Merge pull request #122 from JingleJam/develop
Browse files Browse the repository at this point in the history
Fix calculation bug for Teams donations
  • Loading branch information
no1mann authored Dec 10, 2024
2 parents 39fe21f + cc2272b commit e187526
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
3 changes: 0 additions & 3 deletions website/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,8 @@
}

JingleJam.current = groupBy(points, x => x.year);

console.log(points);
}
catch {
console.log('Error getting current data');
JingleJam.current = [];
}
}
Expand Down
10 changes: 2 additions & 8 deletions workers/tiltify-cache/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,13 @@ async function getSummaryData(env: Env): Promise<ApiResponse> {
}

// Clean up the raised amounts if the total raised amount is different from the sum of all campaign amounts
// This is mainly team donations that are not assigned to a specific campaign
const amountDifference = totalPounds - campaignAmountPounds;
if (amountDifference > 0) {
// Fix the summary data
apiResponse.raised.yogscast += amountDifference;
apiResponse.raised.fundraisers -= amountDifference;

apiResponse.raised.yogscast = roundAmount(apiResponse.raised.yogscast);
apiResponse.raised.fundraisers = roundAmount(apiResponse.raised.fundraisers);

// Fix the cause data
const causeAmount = amountDifference / apiResponse.causes.length;
for (const cause of apiResponse.causes) {
cause.raised.yogscast += causeAmount;
cause.raised.fundraisers += causeAmount;
}
}

Expand Down
15 changes: 12 additions & 3 deletions workers/tiltify-cache/src/do/tiltifyData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,18 @@ export class TiltifyData {
let data: ApiResponse | undefined = await this.storage.get(this.env.DURABLE_OBJECT_CACHE_KEY);

// Update the cached value if it's valid
if(!data || // If the cached value is null
!(newData?.raised?.yogscast == 0 && data?.raised?.yogscast !== 0) // If the raised amount it not valid
) {
if(newData && (
!data || // If the cached value is null
!(newData?.raised?.yogscast == 0 && data?.raised?.yogscast !== 0) // If the raised amount it not valid
)) {
// Check if the campaigns failed to load, if so, keep the old data
if(data && (newData.campaigns.count === 0 && data.campaigns.count > 0)) {
console.log(`Campaigns failed to load... Keeping old data`);

newData.campaigns = data.campaigns;
newData.causes = data.causes;
}

await this.storage.put(this.env.DURABLE_OBJECT_CACHE_KEY, newData);
}

Expand Down

0 comments on commit e187526

Please sign in to comment.