/
schedule.ts
107 lines (106 loc) · 2.33 KB
/
schedule.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
export const scheduleRouter = createTRPCRouter({
fetch: publicProcedure
.input(
z.object({
urlId: z.string(),
})
)
.query(async ({ ctx, input }) => {
const schedules = await ctx.prisma.schedule.findMany({
where: {
urlId: input.urlId,
},
orderBy: {
day: "asc",
},
});
return schedules;
}),
fetchInPeriod: publicProcedure
.input(
z.object({
urlId: z.string(),
startDate: z.date(),
endDate: z.date(),
})
)
.query(async ({ ctx, input }) => {
const schedules = await ctx.prisma.schedule.findMany({
where: {
urlId: input.urlId,
date: {
gte: input.startDate,
lte: input.endDate,
},
},
orderBy: {
day: "asc",
},
});
return schedules;
}),
create: publicProcedure
.input(
z.object({
urlId: z.string(),
day: z.number(),
date: z.date(),
emoji: z.string(),
text: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const schedule = await ctx.prisma.schedule.create({
data: {
urlId: input.urlId,
day: input.day,
date: input.date,
emoji: input.emoji,
text: input.text,
},
});
return schedule;
}),
delete: publicProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const schedule = await ctx.prisma.schedule.delete({
where: {
id: input.id,
},
});
return schedule;
}),
update: publicProcedure
.input(
z.object({
id: z.string(),
urlId: z.string(),
day: z.number(),
date: z.date(),
emoji: z.string(),
text: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const schedule = await ctx.prisma.schedule.update({
where: {
id: input.id,
},
data: {
urlId: input.urlId,
day: input.day,
date: input.date,
emoji: input.emoji,
text: input.text,
},
});
return schedule;
}),
});