-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathapi.v1.queues.ts
More file actions
43 lines (37 loc) · 1.53 KB
/
Copy pathapi.v1.queues.ts
File metadata and controls
43 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { json } from "@remix-run/server-runtime";
import { type QueueItem } from "@trigger.dev/core/v3";
import { z } from "zod";
import { QueueListPresenter } from "~/presenters/v3/QueueListPresenter.server";
import { logger } from "~/services/logger.server";
import { createLoaderApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { ServiceValidationError } from "~/v3/services/baseService.server";
const SearchParamsSchema = z.object({
page: z.coerce.number().int().positive().optional(),
perPage: z.coerce.number().int().positive().optional(),
});
export const loader = createLoaderApiRoute(
{
searchParams: SearchParamsSchema,
findResource: async () => 1, // This is a dummy function, we don't need to find a resource
},
async ({ searchParams, authentication }) => {
const service = new QueueListPresenter(searchParams.perPage);
try {
const result = await service.call({
environment: authentication.environment,
page: searchParams.page ?? 1,
});
if (!result.success) {
return json({ error: result.code }, { status: 400 });
}
const queues: QueueItem[] = result.queues;
return json({ data: queues, pagination: result.pagination }, { status: 200 });
} catch (error) {
if (error instanceof ServiceValidationError) {
return json({ error: error.message }, { status: 422 });
}
logger.error("Failed to list queues", { error });
return json({ error: "Something went wrong, please try again." }, { status: 500 });
}
}
);