|
| 1 | +import type { FastifyInstance } from "fastify"; |
| 2 | +import StatusController from "./status.controller"; |
| 3 | +import StatusService from "./status.service"; |
| 4 | +import { statusSchemas, statusSchemaRef } from "./status.schema"; |
| 5 | + |
| 6 | +export default function StatusRoutes(fastify: FastifyInstance) { |
| 7 | + // Register schemas |
| 8 | + for (const schema of statusSchemas) { |
| 9 | + fastify.addSchema(schema); |
| 10 | + } |
| 11 | + |
| 12 | + const statusController = new StatusController(new StatusService()); |
| 13 | + |
| 14 | + // Create a new status |
| 15 | + fastify.post( |
| 16 | + "/", |
| 17 | + { |
| 18 | + onRequest: [fastify.jwtAuth], |
| 19 | + schema: { |
| 20 | + tags: ["Task Statuses"], |
| 21 | + description: "Create a new task status", |
| 22 | + body: statusSchemaRef("createStatusSchema"), |
| 23 | + response: { |
| 24 | + 201: statusSchemaRef("statusResponse"), |
| 25 | + 400: statusSchemaRef("errorResponse"), |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + // @ts-expect-error - this is a bug in fastify-zod |
| 30 | + statusController.createStatus.bind(statusController) |
| 31 | + ); |
| 32 | + |
| 33 | + // Get all statuses of a project |
| 34 | + fastify.get( |
| 35 | + "/", |
| 36 | + { |
| 37 | + onRequest: [fastify.jwtAuth], |
| 38 | + schema: { |
| 39 | + tags: ["Task Statuses"], |
| 40 | + description: "Get all task statuses of a project", |
| 41 | + params: { |
| 42 | + type: "object", |
| 43 | + properties: { |
| 44 | + projectId: { type: "string" }, |
| 45 | + }, |
| 46 | + required: ["projectId"], |
| 47 | + }, |
| 48 | + response: { |
| 49 | + 200: statusSchemaRef("statusesResponse"), |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + // @ts-expect-error - this is a bug in fastify-zod |
| 54 | + statusController.getStatusesByProjectId.bind(statusController) |
| 55 | + ); |
| 56 | + |
| 57 | + // Update a status |
| 58 | + fastify.put( |
| 59 | + "/:statusId", |
| 60 | + { |
| 61 | + onRequest: [fastify.jwtAuth], |
| 62 | + schema: { |
| 63 | + tags: ["Task Statuses"], |
| 64 | + description: "Update a task status", |
| 65 | + body: statusSchemaRef("updateStatusSchema"), |
| 66 | + response: { |
| 67 | + 200: statusSchemaRef("statusResponse"), |
| 68 | + 400: statusSchemaRef("errorResponse"), |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + // @ts-expect-error - this is a bug in fastify-zod |
| 73 | + statusController.updateStatus.bind(statusController) |
| 74 | + ); |
| 75 | + |
| 76 | + // Delete a status |
| 77 | + fastify.delete( |
| 78 | + "/:statusId", |
| 79 | + { |
| 80 | + onRequest: [fastify.jwtAuth], |
| 81 | + schema: { |
| 82 | + tags: ["Task Statuses"], |
| 83 | + description: "Delete a task status", |
| 84 | + response: { |
| 85 | + 200: statusSchemaRef("statusResponse"), |
| 86 | + 400: statusSchemaRef("errorResponse"), |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + // @ts-expect-error - this is a bug in fastify-zod |
| 91 | + statusController.deleteStatus.bind(statusController) |
| 92 | + ); |
| 93 | +} |
0 commit comments