import { getTask, taskSchema, setTask } from "../../data/index.js";
import { authenticate } from "../authentication.js";
export async function setTaskRoutes(fastify) {
    const params = {
        type: "object",
        properties: {
            taskId: {
                type: "string",
            },
        },
        required: ["taskId"],
    };
    const response = {
        200: {
            description: "Updated task",
            ...taskSchema.task,
        },
    };
    const schema = {
        description: "Update an existing task",
        tags: ["task"],
        summary: "",
        body: taskSchema.taskData,
        response,
        params,
        security: [
            {
                apiKey: [],
            },
        ],
    };
    try {
        fastify.put("/:taskId", {
            schema,
            preHandler: authenticate(fastify),
            async handler(request, response) {
                const { taskId } = request.params;
                const existing = await getTask(taskId);
                const task = await setTask({
                    // Completely replace excluding created at
                    // createdAt must come from the server
                    ...request.body,
                    createdAt: existing?.createdAt,
                    taskId
                });
                response.status(200);
                response.send(task);
            },
        });
    }
    catch { }
}
//# sourceMappingURL=set-task.js.map