|
| 1 | +import type { FastifyInstance } from "fastify"; |
| 2 | +import LabelController from "./label.controller"; |
| 3 | +import LabelService from "./label.service"; |
| 4 | +import { labelSchemas, labelSchemaRef } from "./label.schema"; |
| 5 | + |
| 6 | +export default function LabelsRoute(fastify: FastifyInstance) { |
| 7 | + // Register schemas |
| 8 | + for (const schema of labelSchemas) { |
| 9 | + fastify.addSchema(schema); |
| 10 | + } |
| 11 | + |
| 12 | + const labelController = new LabelController(new LabelService()); |
| 13 | + |
| 14 | + // Create a new task label |
| 15 | + fastify.post( |
| 16 | + "/", |
| 17 | + { |
| 18 | + onRequest: [fastify.jwtAuth], |
| 19 | + schema: { |
| 20 | + tags: ["Task Labels"], |
| 21 | + description: "Create a new task label", |
| 22 | + body: labelSchemaRef("createLabelSchema"), |
| 23 | + response: { |
| 24 | + 201: labelSchemaRef("labelResponse"), |
| 25 | + 400: labelSchemaRef("errorResponse"), |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | + // @ts-expect-error - this is a bug in fastify-zod |
| 30 | + labelController.createLabel.bind(labelController) |
| 31 | + ); |
| 32 | + |
| 33 | + // Get all task labels of a project |
| 34 | + fastify.get( |
| 35 | + "/", |
| 36 | + { |
| 37 | + onRequest: [fastify.jwtAuth], |
| 38 | + schema: { |
| 39 | + tags: ["Task Labels"], |
| 40 | + description: "Get all task labels of a project", |
| 41 | + response: { |
| 42 | + 200: labelSchemaRef("labelsResponse"), |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + // @ts-expect-error - this is a bug in fastify-zod |
| 47 | + labelController.getAllProjectLabels.bind(labelController) |
| 48 | + ); |
| 49 | + |
| 50 | + // Update a task label |
| 51 | + fastify.put( |
| 52 | + "/:labelId", |
| 53 | + { |
| 54 | + onRequest: [fastify.jwtAuth], |
| 55 | + schema: { |
| 56 | + tags: ["Task Labels"], |
| 57 | + description: "Update a task label", |
| 58 | + body: labelSchemaRef("updateLabelSchema"), |
| 59 | + response: { |
| 60 | + 200: labelSchemaRef("labelResponse"), |
| 61 | + 400: labelSchemaRef("errorResponse"), |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + // @ts-expect-error - this is a bug in fastify-zod |
| 66 | + labelController.updateLabel.bind(labelController) |
| 67 | + ); |
| 68 | + |
| 69 | + // Delete a task label |
| 70 | + fastify.delete( |
| 71 | + "/:labelId", |
| 72 | + { |
| 73 | + onRequest: [fastify.jwtAuth], |
| 74 | + schema: { |
| 75 | + tags: ["Task Labels"], |
| 76 | + description: "Delete a task label", |
| 77 | + response: { |
| 78 | + 200: labelSchemaRef("labelResponse"), |
| 79 | + 400: labelSchemaRef("errorResponse"), |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + // @ts-expect-error - this is a bug in fastify-zod |
| 84 | + labelController.deleteLabel.bind(labelController) |
| 85 | + ); |
| 86 | +} |
0 commit comments