mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-15 14:35:06 +00:00
feat: add user groups
This commit is contained in:
43
frontend/src/lib/services/user-group-service.ts
Normal file
43
frontend/src/lib/services/user-group-service.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user