48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import axios from "../http-client";
|
|
import type { FullUser, PartialUser, RecipientChannel, UserId, Uuid } from "../types";
|
|
|
|
export async function me() {
|
|
const response = await axios.get("/users/@me");
|
|
|
|
return response.data as FullUser;
|
|
}
|
|
|
|
export async function getUser(userId: UserId) {
|
|
const response = await axios.get(`/users/${userId}`);
|
|
|
|
return response.data as PartialUser;
|
|
}
|
|
|
|
export async function channels() {
|
|
const response = await axios.get("/users/@me/channels");
|
|
|
|
return response.data as RecipientChannel[];
|
|
}
|
|
|
|
export async function createChannel(recipients: UserId[]) {
|
|
const response = await axios.post("/users/@me/channels", {
|
|
recipients,
|
|
});
|
|
|
|
return response.data as RecipientChannel;
|
|
}
|
|
|
|
interface PatchUserRequest {
|
|
displayName?: string | null;
|
|
avatarId?: Uuid | null;
|
|
}
|
|
|
|
export async function patchUser(request: PatchUserRequest) {
|
|
const response = await axios.patch(`/users/@me`, request);
|
|
|
|
return response.data as FullUser;
|
|
}
|
|
|
|
export default {
|
|
me,
|
|
channels,
|
|
createChannel,
|
|
getUser,
|
|
patchUser,
|
|
};
|