forked from JumboCode/TheLegacyProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c82ba4
commit eca923a
Showing
15 changed files
with
241 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TypedRequest } from "@server/type"; | ||
import { z } from "zod"; | ||
import { editPositionRequest, editPositionResponse } from "./route.schema"; | ||
|
||
export const editPosition = async ( | ||
request: TypedRequest<z.infer<typeof editPositionRequest>>, | ||
uid: string | ||
) => { | ||
const { body, ...options } = request; | ||
const response = await fetch(`/api/user/${uid}/edit-position`, { | ||
method: "PATCH", | ||
body: JSON.stringify(body), | ||
...options, | ||
}); | ||
return editPositionResponse.parse(await response.json()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { z } from "zod"; | ||
|
||
export const editPositionRequest = z.object({ | ||
position: z.string(), | ||
}); | ||
|
||
export const editPositionResponse = z.discriminatedUnion("code", [ | ||
z.object({ | ||
code: z.literal("SUCCESS"), | ||
}), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { prisma } from "@server/db/client"; | ||
import { withRole, withSession } from "@server/decorator"; | ||
import { NextResponse } from "next/server"; | ||
import { editPositionRequest, editPositionResponse } from "./route.schema"; | ||
import { | ||
invalidRequestResponse, | ||
unauthorizedErrorResponse, | ||
} from "@api/route.schema"; | ||
|
||
export const PATCH = withSession( | ||
withRole(["CHAPTER_LEADER"], async ({ session, req, params }) => { | ||
const { user: me } = session; | ||
const otherUid: string = params.params.uid; | ||
const other = await prisma.user.findUnique({ | ||
where: { id: otherUid }, | ||
}); | ||
const request = editPositionRequest.safeParse(await req.json()); | ||
|
||
if (other == null || !request.success) { | ||
return NextResponse.json(invalidRequestResponse, { status: 400 }); | ||
} | ||
|
||
if (me.role !== "CHAPTER_LEADER" || me.ChapterID !== other.ChapterID) { | ||
return NextResponse.json(unauthorizedErrorResponse, { status: 401 }); | ||
} | ||
|
||
await prisma.user.update({ | ||
where: { | ||
id: otherUid, | ||
}, | ||
data: { | ||
position: request.data.position, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(editPositionResponse.parse({ code: "SUCCESS" })); | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
interface PopupProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Popup = (props: PopupProps) => { | ||
return ( | ||
<div className="fixed left-0 top-0 z-50 flex h-screen w-screen items-center justify-center backdrop-blur-[2px] backdrop-brightness-75"> | ||
<div className="flex h-48 w-[30rem] flex-col gap-y-6 rounded-[16px] bg-dark-teal px-6 py-9"> | ||
{props.children} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Popup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as HeaderContainer } from "./HeaderContainer"; | ||
export { default as CardGrid } from "./CardGrid"; | ||
export { default as CollapsableSidebarContainer } from "./CollapsableSidebarContainer"; | ||
export { default as Popup } from "./Popup"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.