2025-10-13 11:12:55 +02:00
|
|
|
import type { ListRequestOptions, Paginated } from '$lib/types/list-request.type';
|
2024-10-02 08:43:44 +02:00
|
|
|
import type {
|
|
|
|
|
UserGroupCreate,
|
|
|
|
|
UserGroupWithUserCount,
|
|
|
|
|
UserGroupWithUsers
|
|
|
|
|
} from '$lib/types/user-group.type';
|
|
|
|
|
import APIService from './api-service';
|
|
|
|
|
|
|
|
|
|
export default class UserGroupService extends APIService {
|
2025-10-13 11:12:55 +02:00
|
|
|
list = async (options?: ListRequestOptions) => {
|
|
|
|
|
const res = await this.api.get('/user-groups', { params: options });
|
2024-10-02 08:43:44 +02:00
|
|
|
return res.data as Paginated<UserGroupWithUserCount>;
|
2025-10-13 11:12:55 +02:00
|
|
|
};
|
2024-10-02 08:43:44 +02:00
|
|
|
|
2025-10-13 11:12:55 +02:00
|
|
|
get = async (id: string) => {
|
2024-10-02 08:43:44 +02:00
|
|
|
const res = await this.api.get(`/user-groups/${id}`);
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
2025-10-13 11:12:55 +02:00
|
|
|
};
|
2024-10-02 08:43:44 +02:00
|
|
|
|
2025-10-13 11:12:55 +02:00
|
|
|
create = async (user: UserGroupCreate) => {
|
2024-10-02 08:43:44 +02:00
|
|
|
const res = await this.api.post('/user-groups', user);
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
2025-10-13 11:12:55 +02:00
|
|
|
};
|
2024-10-02 08:43:44 +02:00
|
|
|
|
2025-10-13 11:12:55 +02:00
|
|
|
update = async (id: string, user: UserGroupCreate) => {
|
2024-10-02 08:43:44 +02:00
|
|
|
const res = await this.api.put(`/user-groups/${id}`, user);
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
2025-10-13 11:12:55 +02:00
|
|
|
};
|
2024-10-02 08:43:44 +02:00
|
|
|
|
2025-10-13 11:12:55 +02:00
|
|
|
remove = async (id: string) => {
|
2024-10-02 08:43:44 +02:00
|
|
|
await this.api.delete(`/user-groups/${id}`);
|
2025-10-13 11:12:55 +02:00
|
|
|
};
|
2024-10-02 08:43:44 +02:00
|
|
|
|
2025-10-13 11:12:55 +02:00
|
|
|
updateUsers = async (id: string, userIds: string[]) => {
|
2024-10-02 08:43:44 +02:00
|
|
|
const res = await this.api.put(`/user-groups/${id}/users`, { userIds });
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
2025-10-13 11:12:55 +02:00
|
|
|
};
|
2024-10-02 08:43:44 +02:00
|
|
|
}
|