This commit is contained in:
Your Name committed 2026-06-28 20:18:07 -04:00
1 parent 6096c727d9
commit 3965f4f4da
38 files changed
+1513 -752

No files matched your search

+24
View File
@@ -164,6 +164,30 @@ export const categoriesRoute = new Elysia({ prefix: "/categories" })
return status(500, { message: err?.message || "Failed to update translations" });
}
})
.patch("/:id/image", async ({ params, body, status }) => {
const id = parseInt(params.id);
if (isNaN(id)) return status(400, { message: "Invalid category ID" });
try {
const category = await prisma.category.update({
where: { id },
data: {
imageUrl: body.imageUrl,
},
});
return category;
} catch (err: any) {
if (err.code === "P2025") {
return status(404, { message: "Category not found" });
}
console.error("Update category image error:", err);
return status(500, { message: "Failed to update category image" });
}
}, {
body: t.Object({
imageUrl: t.Union([t.String(), t.Null()]),
})
})
.post("/", async ({ body, status }) => {
try {
const category = await prisma.category.create({
+69
View File
@@ -0,0 +1,69 @@
import prisma from "./src/lib/prisma";
import { categoriesRoute } from "./src/routes/categories";
async function test() {
console.log("Creating/Finding test category...");
// Let's find or create a category
let category = await prisma.category.findFirst({
where: {
name: "TestCategoryTemp"
}
});
if (!category) {
category = await prisma.category.create({
data: {
name: "TestCategoryTemp",
translations: { create: { langCode: "th", name: "TestCategoryTemp" } }
}
});
}
const id = category.id;
console.log(`Using category ID: ${id}, current imageUrl: ${category.imageUrl}`);
// Test updating image URL to a new value
console.log("Updating imageUrl to 'https://example.com/test.png'...");
const updateRes = await categoriesRoute.handle(
new Request(`http://localhost/categories/${id}/image`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ imageUrl: "https://example.com/test.png" })
})
);
console.log("PATCH status:", updateRes.status);
const updatedCategory = await updateRes.json();
console.log("PATCH response:", updatedCategory);
if (updatedCategory.imageUrl !== "https://example.com/test.png") {
throw new Error("imageUrl was not updated correctly!");
}
// Test setting imageUrl to null
console.log("Updating imageUrl to null...");
const nullRes = await categoriesRoute.handle(
new Request(`http://localhost/categories/${id}/image`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ imageUrl: null })
})
);
console.log("PATCH null status:", nullRes.status);
const nulledCategory = await nullRes.json();
console.log("PATCH null response:", nulledCategory);
if (nulledCategory.imageUrl !== null) {
throw new Error("imageUrl was not nulled correctly!");
}
// Clean up if we created the temp category
if (category.name === "TestCategoryTemp") {
await prisma.category.delete({ where: { id } });
console.log("Cleaned up temp category.");
}
console.log("All PATCH tests passed successfully!");
}
test().catch(console.error);
+21
View File
@@ -130,6 +130,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
required: ["id", "lang", "name"]
}
},
{
name: "update_category_image",
description: "Update the image URL for a specific category.",
inputSchema: {
type: "object",
properties: {
id: { type: "number", description: "Category ID" },
imageUrl: { type: ["string", "null"], description: "New image URL, or null/empty string to remove the image" }
},
required: ["id", "imageUrl"]
}
},
{
name: "update_product_brand_translation",
description: "Add or update translations for a specific product brand.",
@@ -868,6 +880,15 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
content: [{ type: "text", text: JSON.stringify(res.data, null, 2) }]
};
}
case "update_category_image": {
const { id, imageUrl } = params as any;
const res = await api.patch(`/categories/${id}/image`, {
imageUrl: imageUrl || null
});
return {
content: [{ type: "text", text: JSON.stringify(res.data, null, 2) }]
};
}
case "update_product_brand_translation": {
const { id, lang, name } = params as any;
const res = await api.patch(`/products/brands/${id}/translations`, {
@@ -0,0 +1,91 @@
import { spawn } from "child_process";
async function test() {
console.log("Starting backend server...");
const backend = spawn("bun", ["src/index.ts"], {
cwd: "../backend",
env: { ...process.env, PORT: "3051" }
});
// Give backend 2 seconds to start
await new Promise(resolve => setTimeout(resolve, 2000));
console.log("Starting MCP server...");
const mcp = spawn("bun", ["index.ts"], {
cwd: ".",
env: { ...process.env, MCP_BACKEND_URL: "http://localhost:3051/api" }
});
mcp.stderr.on("data", (data) => {
console.error(`[MCP STDERR] ${data}`);
});
let responseData = "";
mcp.stdout.on("data", (data) => {
responseData += data.toString();
console.log(`[MCP STDOUT] ${data}`);
});
const send = (msg: any) => {
mcp.stdin.write(JSON.stringify(msg) + "\n");
};
// 1. Send initialize
console.log("Sending initialize request...");
send({
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: { name: "test-client", version: "1.0.0" }
}
});
await new Promise(resolve => setTimeout(resolve, 1000));
// 2. Send initialized notification
console.log("Sending initialized notification...");
send({
jsonrpc: "2.0",
method: "notifications/initialized"
});
await new Promise(resolve => setTimeout(resolve, 1000));
// 3. Send callTool request to update_category_image
console.log("Sending callTool request for update_category_image...");
responseData = ""; // Clear response data
send({
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "update_category_image",
arguments: {
id: 1,
imageUrl: "https://example.com/mcp-test.png"
}
}
});
await new Promise(resolve => setTimeout(resolve, 3000));
console.log("Cleaning up servers...");
mcp.kill();
backend.kill();
console.log("Verifying response...");
console.log("Full responseData:", responseData);
if (!responseData.includes("https://example.com/mcp-test.png")) {
throw new Error("MCP response did not contain the updated imageUrl!");
}
console.log("MCP tool test passed successfully!");
}
test().catch(err => {
console.error("Test failed:", err);
process.exit(1);
});