2025-01-11 20:14:12 +01:00
|
|
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.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-01-11 20:14:12 +01:00
|
|
|
async list(options?: SearchPaginationSortRequest) {
|
2024-10-02 08:43:44 +02:00
|
|
|
const res = await this.api.get('/user-groups', {
|
2025-01-11 20:14:12 +01:00
|
|
|
params: options
|
2024-10-02 08:43:44 +02:00
|
|
|
});
|
|
|
|
|
return res.data as Paginated<UserGroupWithUserCount>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async get(id: string) {
|
|
|
|
|
const res = await this.api.get(`/user-groups/${id}`);
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async create(user: UserGroupCreate) {
|
|
|
|
|
const res = await this.api.post('/user-groups', user);
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async update(id: string, user: UserGroupCreate) {
|
|
|
|
|
const res = await this.api.put(`/user-groups/${id}`, user);
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async remove(id: string) {
|
|
|
|
|
await this.api.delete(`/user-groups/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateUsers(id: string, userIds: string[]) {
|
|
|
|
|
const res = await this.api.put(`/user-groups/${id}/users`, { userIds });
|
|
|
|
|
return res.data as UserGroupWithUsers;
|
|
|
|
|
}
|
|
|
|
|
}
|