Files
task-manager/server/routes.ts
T
paul-nothaft 6ff53e071a
continuous-integration/drone/push Build is passing
Fix Docker deployment by resolving module resolution errors
Update build process and imports to ensure Node.js ESM compatibility for Docker deployments, addressing ERR_MODULE_NOT_FOUND errors by separating server compilation and adding .js extensions to all relative imports.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ceced2fc-aa46-458d-ba87-ddd4b7bb1518
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/659922a9-0087-461c-90dd-6d9a58b81d4d/ceced2fc-aa46-458d-ba87-ddd4b7bb1518/SBF5OKZ
2025-10-23 15:09:58 +00:00

146 lines
4.3 KiB
TypeScript

import type { Express } from "express";
import { createServer, type Server } from "http";
import { storage } from "./storage.js";
import { insertLabelSchema, insertTaskSchema } from "../shared/schema.js";
export async function registerRoutes(app: Express): Promise<Server> {
// Health check endpoint
app.get("/api/health", (req, res) => {
res.status(200).json({ status: "ok", timestamp: new Date().toISOString() });
});
// Labels API routes
app.get("/api/labels", async (req, res) => {
try {
const labels = await storage.getAllLabels();
res.json(labels);
} catch (error) {
res.status(500).json({ error: "Failed to fetch labels" });
}
});
app.get("/api/labels/:id", async (req, res) => {
try {
const label = await storage.getLabel(req.params.id);
if (!label) {
return res.status(404).json({ error: "Label not found" });
}
res.json(label);
} catch (error) {
res.status(500).json({ error: "Failed to fetch label" });
}
});
app.post("/api/labels", async (req, res) => {
try {
const result = insertLabelSchema.safeParse(req.body);
if (!result.success) {
return res.status(400).json({ error: "Invalid label data", details: result.error });
}
const label = await storage.createLabel(result.data);
res.status(201).json(label);
} catch (error) {
res.status(500).json({ error: "Failed to create label" });
}
});
app.patch("/api/labels/:id", async (req, res) => {
try {
const updates = insertLabelSchema.partial().safeParse(req.body);
if (!updates.success) {
return res.status(400).json({ error: "Invalid label data", details: updates.error });
}
const label = await storage.updateLabel(req.params.id, updates.data);
if (!label) {
return res.status(404).json({ error: "Label not found" });
}
res.json(label);
} catch (error) {
res.status(500).json({ error: "Failed to update label" });
}
});
app.delete("/api/labels/:id", async (req, res) => {
try {
const success = await storage.deleteLabel(req.params.id);
if (!success) {
return res.status(404).json({ error: "Label not found" });
}
res.status(204).send();
} catch (error) {
res.status(500).json({ error: "Failed to delete label" });
}
});
// Tasks API routes
app.get("/api/tasks", async (req, res) => {
try {
const tasks = await storage.getAllTasks();
res.json(tasks);
} catch (error) {
res.status(500).json({ error: "Failed to fetch tasks" });
}
});
app.get("/api/tasks/:id", async (req, res) => {
try {
const task = await storage.getTask(req.params.id);
if (!task) {
return res.status(404).json({ error: "Task not found" });
}
res.json(task);
} catch (error) {
res.status(500).json({ error: "Failed to fetch task" });
}
});
app.post("/api/tasks", async (req, res) => {
try {
const result = insertTaskSchema.safeParse(req.body);
if (!result.success) {
return res.status(400).json({ error: "Invalid task data", details: result.error });
}
const task = await storage.createTask(result.data);
res.status(201).json(task);
} catch (error) {
res.status(500).json({ error: "Failed to create task" });
}
});
app.patch("/api/tasks/:id", async (req, res) => {
try {
const updates = insertTaskSchema.partial().safeParse(req.body);
if (!updates.success) {
return res.status(400).json({ error: "Invalid task data", details: updates.error });
}
const task = await storage.updateTask(req.params.id, updates.data);
if (!task) {
return res.status(404).json({ error: "Task not found" });
}
res.json(task);
} catch (error) {
res.status(500).json({ error: "Failed to update task" });
}
});
app.delete("/api/tasks/:id", async (req, res) => {
try {
const success = await storage.deleteTask(req.params.id);
if (!success) {
return res.status(404).json({ error: "Task not found" });
}
res.status(204).send();
} catch (error) {
res.status(500).json({ error: "Failed to delete task" });
}
});
const httpServer = createServer(app);
return httpServer;
}