From 30d1892a7d7c27b370c56ad82eb5b62d7901aed9 Mon Sep 17 00:00:00 2001 From: Hammer Date: Fri, 30 Jan 2026 13:56:30 +0000 Subject: [PATCH] fix: reorder migrate-owner route before /:id param route --- backend/src/routes/todos.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/backend/src/routes/todos.ts b/backend/src/routes/todos.ts index 30eb376..b71ea67 100644 --- a/backend/src/routes/todos.ts +++ b/backend/src/routes/todos.ts @@ -142,6 +142,24 @@ export const todoRoutes = new Elysia({ prefix: "/api/todos" }) }) // PATCH update todo + // POST reassign all bearer todos to a real user (one-time migration) + .post("/migrate-owner", async ({ body, request, headers }) => { + const { userId } = await requireSessionOrBearer(request, headers); + + const result = await db + .update(todos) + .set({ userId: body.targetUserId, updatedAt: new Date() }) + .where(eq(todos.userId, body.fromUserId)) + .returning({ id: todos.id }); + + return { migrated: result.length }; + }, { + body: t.Object({ + fromUserId: t.String(), + targetUserId: t.String(), + }), + }) + .patch("/:id", async ({ params, body, request, headers }) => { const { userId } = await requireSessionOrBearer(request, headers); @@ -279,20 +297,3 @@ export const todoRoutes = new Elysia({ prefix: "/api/todos" }) }), }) - // POST reassign all bearer todos to a real user (one-time migration) - .post("/migrate-owner", async ({ body, request, headers }) => { - const { userId } = await requireSessionOrBearer(request, headers); - - const result = await db - .update(todos) - .set({ userId: body.targetUserId, updatedAt: new Date() }) - .where(eq(todos.userId, body.fromUserId)) - .returning({ id: todos.id }); - - return { migrated: result.length }; - }, { - body: t.Object({ - fromUserId: t.String(), - targetUserId: t.String(), - }), - });