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 },
|
2023-11-10 01:55:08 +00:00
|
|
|
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
|
|
|
});
|