Skip to content

Commit 610a706

Browse files
authored
Schedules (#247)
1 parent a5e332b commit 610a706

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/schema/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import "./salary/mutations";
3030
import "./salary/queries";
3131
import "./salary/types";
3232
import "./schedules/types";
33+
import "./schedules/queries";
3334
import "./sessions/types";
3435
import "./speakers/types";
3536
import "./status/types";

src/schema/schedules/queries.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { builder } from "~/builder";
2+
import { selectScheduleSchema } from "~/datasources/db/schema";
3+
import { applicationError, ServiceErrors } from "~/errors";
4+
import { schedulesFetcher } from "~/schema/schedules/schedulesFetcher";
5+
import { ScheduleRef } from "~/schema/schedules/types";
6+
7+
builder.queryField("schedule", (t) =>
8+
t.field({
9+
description: "Get a schedule by its ID",
10+
type: ScheduleRef,
11+
args: {
12+
scheduleId: t.arg.string({ required: true }),
13+
},
14+
resolve: async (root, { scheduleId }, { DB, logger }) => {
15+
const schedules = await schedulesFetcher.searchSchedules({
16+
DB,
17+
search: { scheduleIds: [scheduleId] },
18+
});
19+
const schedule = schedules[0];
20+
21+
if (!schedule) {
22+
throw applicationError(
23+
"Schedule not found",
24+
ServiceErrors.NOT_FOUND,
25+
logger,
26+
);
27+
}
28+
29+
return selectScheduleSchema.parse(schedule);
30+
},
31+
}),
32+
);

0 commit comments

Comments
 (0)