Files
pocket-id-pocket-id/frontend/src/lib/services/user-group-service.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

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 {
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>;
};
2024-10-02 08:43:44 +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;
};
2024-10-02 08:43:44 +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;
};
2024-10-02 08:43:44 +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;
};
2024-10-02 08:43:44 +02:00
remove = async (id: string) => {
2024-10-02 08:43:44 +02:00
await this.api.delete(`/user-groups/${id}`);
};
2024-10-02 08:43:44 +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;
};
2024-10-02 08:43:44 +02:00
}