UNPKG

create-cloudflare

Version:

A CLI for creating and deploying new applications to Cloudflare.

70 lines (64 loc) 1.4 kB
import { Bool, Num, OpenAPIRoute } from "chanfana"; import { z } from "zod"; import { type AppContext, Task } from "../types"; export class TaskList extends OpenAPIRoute { schema = { tags: ["Tasks"], summary: "List Tasks", request: { query: z.object({ page: Num({ description: "Page number", default: 0, }), isCompleted: Bool({ description: "Filter by completed flag", required: false, }), }), }, responses: { "200": { description: "Returns a list of tasks", content: { "application/json": { schema: z.object({ series: z.object({ success: Bool(), result: z.object({ tasks: Task.array(), }), }), }), }, }, }, }, }; async handle(c: AppContext) { // Get validated data const data = await this.getValidatedData<typeof this.schema>(); // Retrieve the validated parameters const { page, isCompleted } = data.query; // Implement your own object list here return { success: true, tasks: [ { name: "Clean my room", slug: "clean-room", description: null, completed: false, due_date: "2025-01-05", }, { name: "Build something awesome with Cloudflare Workers", slug: "cloudflare-workers", description: "Lorem Ipsum", completed: true, due_date: "2022-12-24", }, ], }; } }