mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 10:33:01 +00:00
update user backend + frontend server function
This commit is contained in:
@@ -8,7 +8,7 @@ import issues from "./issues/all";
|
||||
import issuesByProject from "./issues/by-project";
|
||||
import organisationAddMember from "./organisation/add-member";
|
||||
import organisationById from "./organisation/by-id";
|
||||
import organisationByUser from "./organisation/by-user";
|
||||
import organisationsByUser from "./organisation/by-user";
|
||||
import organisationCreate from "./organisation/create";
|
||||
import organisationDelete from "./organisation/delete";
|
||||
import organisationMembers from "./organisation/members";
|
||||
@@ -23,8 +23,15 @@ import projectDelete from "./project/delete";
|
||||
import projectUpdate from "./project/update";
|
||||
import projectWithCreator from "./project/with-creator";
|
||||
import projectsWithCreators from "./project/with-creators";
|
||||
import userUpdate from "./user/update";
|
||||
|
||||
export const routes = {
|
||||
authRegister,
|
||||
authLogin,
|
||||
authMe,
|
||||
|
||||
userUpdate,
|
||||
|
||||
issueCreate,
|
||||
issueDelete,
|
||||
issueUpdate,
|
||||
@@ -34,7 +41,6 @@ export const routes = {
|
||||
|
||||
organisationCreate,
|
||||
organisationById,
|
||||
organisationByUser,
|
||||
organisationUpdate,
|
||||
organisationDelete,
|
||||
organisationAddMember,
|
||||
@@ -42,16 +48,15 @@ export const routes = {
|
||||
organisationRemoveMember,
|
||||
organisationUpdateMemberRole,
|
||||
|
||||
organisationsByUser,
|
||||
|
||||
projectCreate,
|
||||
projectUpdate,
|
||||
projectDelete,
|
||||
projectWithCreator,
|
||||
|
||||
projectsByCreator,
|
||||
projectsByOrganisation,
|
||||
projectsAll,
|
||||
projectsWithCreators,
|
||||
projectWithCreator,
|
||||
|
||||
authRegister,
|
||||
authLogin,
|
||||
authMe,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { AuthedRequest } from "../../auth/middleware";
|
||||
import { getOrganisationsByUserId, getUserById } from "../../db/queries";
|
||||
|
||||
// /organisation/by-user?userId=1
|
||||
// /organisations/by-user?userId=1
|
||||
export default async function organisationsByUser(req: AuthedRequest) {
|
||||
const url = new URL(req.url);
|
||||
const userId = url.searchParams.get("userId");
|
||||
|
||||
30
packages/backend/src/routes/user/update.ts
Normal file
30
packages/backend/src/routes/user/update.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { UserRecord } from "@issue/shared";
|
||||
import type { AuthedRequest } from "../../auth/middleware";
|
||||
import { getUserById } from "../../db/queries";
|
||||
|
||||
// /user/update?id=1&name=NewName&passwordHash=NewHash&serverURL=NewURL
|
||||
export default async function update(req: AuthedRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
if (!id) {
|
||||
return new Response("id is required", { status: 400 });
|
||||
}
|
||||
|
||||
const user = await getUserById(Number(id));
|
||||
if (!user) {
|
||||
return new Response("user not found", { status: 404 });
|
||||
}
|
||||
|
||||
const name = url.searchParams.get("name") || undefined;
|
||||
const passwordHash = url.searchParams.get("passwordHash") || undefined;
|
||||
const serverURL = url.searchParams.get("serverURL") || undefined;
|
||||
|
||||
const { updateById } = await import("../../db/queries/users");
|
||||
const updatedUser = await updateById(user.id, { name, passwordHash, serverURL });
|
||||
|
||||
if (!updatedUser) {
|
||||
return new Response("failed to update user", { status: 500 });
|
||||
}
|
||||
|
||||
return Response.json(updatedUser as UserRecord);
|
||||
}
|
||||
Reference in New Issue
Block a user