From e270a3ab1f6d7b8ef6b60837dd8ba6cb9709d105 Mon Sep 17 00:00:00 2001 From: nameless Date: Fri, 10 Nov 2023 01:55:08 +0000 Subject: [PATCH] refactor: optimize jobs endpoint output --- api/jobsRoute.ts | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/api/jobsRoute.ts b/api/jobsRoute.ts index cc85982..e7811c4 100644 --- a/api/jobsRoute.ts +++ b/api/jobsRoute.ts @@ -4,12 +4,29 @@ import { generationQueue } from "../app/generationQueue.ts"; export const jobsRoute = createMethodFilter({ GET: createEndpoint( { query: null, body: null }, - async () => ({ - status: 200, - body: { - type: "application/json", - data: await generationQueue.getAllJobs(), - }, - }), + async () => { + const allJobs = await generationQueue.getAllJobs(); + const filteredJobsData = allJobs.map((job) => ({ + id: job.id, + place: job.place, + state: { + from: { + language_code: job.state.from.language_code, + first_name: job.state.from.first_name, + last_name: job.state.from.last_name, + username: job.state.from.username, + }, + progress: job.state.progress, + workerInstanceKey: job.state.workerInstanceKey, + }, + })); + return { + status: 200, + body: { + type: "application/json", + data: filteredJobsData, + }, + }; + }, ), });