From 186224eb525af51d748474bf7487c40a4387264f 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, + }, + }; + }, ), }); -- 2.43.5