Add user management

This commit is contained in:
2026-05-02 14:31:19 +02:00
parent 24ade563db
commit 5997a29d92
20 changed files with 983 additions and 2 deletions
+62
View File
@@ -0,0 +1,62 @@
import { makeApiUrl } from '.';
import type { CreateUserRequest, UpdateUserRequest, User } from './types/user';
export const getUsers = async (): Promise<User[]> => {
const response = await fetch(makeApiUrl('/users'), {
method: 'GET',
});
if (response.status === 404) {
return [];
}
if (!response.ok) {
throw new Error('Failed to fetch sites');
}
return response.json();
};
export const getUserById = async (id: string): Promise<User> => {
const response = await fetch(makeApiUrl(`/users/${id}`), {
method: 'GET',
});
if (!response.ok) {
throw new Error('Failed to fetch user');
}
return response.json();
};
export const createUser = async (data: CreateUserRequest): Promise<User> => {
const response = await fetch(makeApiUrl('/users'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error('Failed to create user');
}
return response.json();
};
export const updateUser = async (id: string, data: Partial<UpdateUserRequest>): Promise<User> => {
const response = await fetch(makeApiUrl(`/users/${id}`), {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error('Failed to update user');
}
return response.json();
};
export const deleteUser = async (id: string): Promise<void> => {
const response = await fetch(makeApiUrl(`/users/${id}`), {
method: 'DELETE',
});
if (!response.ok) {
throw new Error('Failed to delete user');
}
};