forked from pinks/eris
1
0
Fork 0

refactor: optimize jobs endpoint output #6

Merged
nameless merged 1 commits from jobs-route-fix into pr-main 2023-11-10 23:45:04 +00:00
1 changed files with 24 additions and 7 deletions
Showing only changes of commit 186224eb52 - Show all commits

View File

@ -4,12 +4,29 @@ import { generationQueue } from "../app/generationQueue.ts";
export const jobsRoute = createMethodFilter({ export const jobsRoute = createMethodFilter({
GET: createEndpoint( GET: createEndpoint(
{ query: null, body: null }, { query: null, body: null },
async () => ({ 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, status: 200,
body: { body: {
type: "application/json", type: "application/json",
data: await generationQueue.getAllJobs(), data: filteredJobsData,
},
};
}, },
}),
), ),
}); });