fix: reorder migrate-owner route before /:id param route
This commit is contained in:
@@ -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(),
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user