A Cloudflare Worker which works in conjunction with https://github.com/indexxing/bsky-alt-text
1import { Bool, OpenAPIRoute } from "chanfana";
2import { z } from "zod";
3import { type AppContext, Task } from "../types";
4
5export class TaskCreate extends OpenAPIRoute {
6 schema = {
7 tags: ["Tasks"],
8 summary: "Create a new Task",
9 request: {
10 body: {
11 content: {
12 "application/json": {
13 schema: Task,
14 },
15 },
16 },
17 },
18 responses: {
19 "200": {
20 description: "Returns the created task",
21 content: {
22 "application/json": {
23 schema: z.object({
24 series: z.object({
25 success: Bool(),
26 result: z.object({
27 task: Task,
28 }),
29 }),
30 }),
31 },
32 },
33 },
34 },
35 };
36
37 async handle(c: AppContext) {
38 // Get validated data
39 const data = await this.getValidatedData<typeof this.schema>();
40
41 // Retrieve the validated request body
42 const taskToCreate = data.body;
43
44 // Implement your own object insertion here
45
46 // return the new task
47 return {
48 success: true,
49 task: {
50 name: taskToCreate.name,
51 slug: taskToCreate.slug,
52 description: taskToCreate.description,
53 completed: taskToCreate.completed,
54 due_date: taskToCreate.due_date,
55 },
56 };
57 }
58}