forked from pinks/eris
1
0
Fork 0
nyx/api/jobsRoute.ts

33 lines
939 B
TypeScript
Raw Normal View History

2023-10-08 21:23:54 +00:00
import { createEndpoint, createMethodFilter } from "t_rest/server";
2023-10-05 09:00:51 +00:00
import { generationQueue } from "../app/generationQueue.ts";
2023-10-08 21:23:54 +00:00
export const jobsRoute = createMethodFilter({
GET: createEndpoint(
2023-10-05 09:00:51 +00:00
{ query: null, body: null },
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,
},
};
},
2023-10-05 09:00:51 +00:00
),
2023-10-08 21:23:54 +00:00
});