Some checks failed
CI / test (push) Failing after 18s
- add user_contacts table and migration - expose /users/contacts list/add/remove endpoints - add Contacts tab in chat list with add/remove actions
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { http } from "./http";
|
|
import type { AuthUser, UserSearchItem } from "../chat/types";
|
|
|
|
export async function searchUsers(query: string, limit = 20): Promise<UserSearchItem[]> {
|
|
const { data } = await http.get<UserSearchItem[]>("/users/search", {
|
|
params: { query, limit }
|
|
});
|
|
return data;
|
|
}
|
|
|
|
interface UserProfileUpdatePayload {
|
|
name?: string;
|
|
username?: string;
|
|
bio?: string | null;
|
|
avatar_url?: string | null;
|
|
allow_private_messages?: boolean;
|
|
}
|
|
|
|
export async function updateMyProfile(payload: UserProfileUpdatePayload): Promise<AuthUser> {
|
|
const { data } = await http.put<AuthUser>("/users/profile", payload);
|
|
return data;
|
|
}
|
|
|
|
export async function getUserById(userId: number): Promise<AuthUser> {
|
|
const { data } = await http.get<AuthUser>(`/users/${userId}`);
|
|
return data;
|
|
}
|
|
|
|
export async function listBlockedUsers(): Promise<UserSearchItem[]> {
|
|
const { data } = await http.get<UserSearchItem[]>("/users/blocked");
|
|
return data;
|
|
}
|
|
|
|
export async function blockUser(userId: number): Promise<void> {
|
|
await http.post(`/users/${userId}/block`);
|
|
}
|
|
|
|
export async function unblockUser(userId: number): Promise<void> {
|
|
await http.delete(`/users/${userId}/block`);
|
|
}
|
|
|
|
export async function listContacts(): Promise<UserSearchItem[]> {
|
|
const { data } = await http.get<UserSearchItem[]>("/users/contacts");
|
|
return data;
|
|
}
|
|
|
|
export async function addContact(userId: number): Promise<void> {
|
|
await http.post(`/users/${userId}/contacts`);
|
|
}
|
|
|
|
export async function removeContact(userId: number): Promise<void> {
|
|
await http.delete(`/users/${userId}/contacts`);
|
|
}
|