mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-14 09:13:21 +03:00
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import type { Paginated, PaginationRequest } from '$lib/types/pagination.type';
|
|
import type {
|
|
UserGroupCreate,
|
|
UserGroupWithUserCount,
|
|
UserGroupWithUsers
|
|
} from '$lib/types/user-group.type';
|
|
import APIService from './api-service';
|
|
|
|
export default class UserGroupService extends APIService {
|
|
async list(search?: string, pagination?: PaginationRequest) {
|
|
const res = await this.api.get('/user-groups', {
|
|
params: {
|
|
search,
|
|
...pagination
|
|
}
|
|
});
|
|
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;
|
|
}
|
|
}
|