mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-08 08:56:39 -05:00
feat: add progress endpoint
This commit is contained in:
53
server/api/progress.get.ts
Normal file
53
server/api/progress.get.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import type { GetProgress, ProgressItem } from "#shared/api-types"
|
||||
import { getGithubProjects } from "../utils/getGithubProgress";
|
||||
import { getStripeDonations } from "../utils/getStripeDonations";
|
||||
|
||||
const donationGoalCents = 3000 * 100;
|
||||
|
||||
export default defineEventHandler(async (event): Promise<GetProgress> => {
|
||||
const octokit = useOctokit(event);
|
||||
const stripe = useStripe(event);
|
||||
const donationData = await getStripeDonations(stripe);
|
||||
const { projects } = await getGithubProjects(octokit);
|
||||
|
||||
const items: ProgressItem[] = projects.map(v => {
|
||||
const totalTasks = v.tasks.length;
|
||||
const completedTasks = v.tasks.filter(v => v.status === 'completed').length;
|
||||
const percentage = Math.floor(completedTasks / totalTasks * 100);
|
||||
|
||||
return {
|
||||
title: v.title,
|
||||
githubUrl: v.url,
|
||||
completion: percentage,
|
||||
tasks: v.tasks.map(task => ({
|
||||
status: task.status,
|
||||
title: task.title,
|
||||
}))
|
||||
}
|
||||
});
|
||||
const summedCompletion = items.reduce((a, v) => a + v.completion, 0);
|
||||
const completionPercentage = Math.floor(summedCompletion / items.length * 100);
|
||||
|
||||
return {
|
||||
completion: completionPercentage,
|
||||
donations: {
|
||||
currentCents: donationData.totalDonationsCents,
|
||||
goalCents: donationGoalCents,
|
||||
},
|
||||
items: projects.map(v => {
|
||||
const totalTasks = v.tasks.length;
|
||||
const completedTasks = v.tasks.filter(v => v.status === 'completed').length;
|
||||
const percentage = Math.floor(completedTasks / totalTasks * 100);
|
||||
|
||||
return {
|
||||
title: v.title,
|
||||
githubUrl: v.url,
|
||||
completion: percentage,
|
||||
tasks: v.tasks.map(task => ({
|
||||
status: task.status,
|
||||
title: task.title,
|
||||
}))
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user