feat(api): add account mutation clients
This commit is contained in:
+22
-2
@@ -1,10 +1,16 @@
|
||||
import { httpJson } from "@/lib/api/http"
|
||||
import { isApiError } from "@/lib/errors"
|
||||
import type { User } from "@/lib/types"
|
||||
import type { User, UserRole } from "@/lib/types"
|
||||
|
||||
export type UpdateCurrentUserInput = {
|
||||
nickname?: string
|
||||
avatar?: string
|
||||
bio?: string
|
||||
}
|
||||
|
||||
export async function getUserById(userId: string): Promise<User | undefined> {
|
||||
try {
|
||||
return await httpJson<User>(`/api/v1/users/${userId}`)
|
||||
return await httpJson<User>(`/api/v1/users/${encodeURIComponent(userId)}`)
|
||||
} catch (err) {
|
||||
if (isApiError(err) && err.code === 404) return undefined
|
||||
throw err
|
||||
@@ -14,3 +20,17 @@ export async function getUserById(userId: string): Promise<User | undefined> {
|
||||
export async function getCurrentUserForLogin(): Promise<User> {
|
||||
return httpJson<User>("/api/v1/users/me")
|
||||
}
|
||||
|
||||
export async function updateCurrentUser(input: UpdateCurrentUserInput): Promise<User> {
|
||||
return httpJson<User>("/api/v1/users/me", {
|
||||
method: "PUT",
|
||||
json: input,
|
||||
})
|
||||
}
|
||||
|
||||
export async function switchCurrentRole(role: UserRole): Promise<void> {
|
||||
await httpJson<unknown>("/api/v1/users/me/switch-role", {
|
||||
method: "POST",
|
||||
json: { role },
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user