-
-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathgroup.ts
More file actions
119 lines (110 loc) · 3.39 KB
/
group.ts
File metadata and controls
119 lines (110 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Fetch data for group management
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2023-2026 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2023-01-02
*/
import { CategoryItem, CategoryRestrictions, Group, Member, User } from '../interfaces';
import { fetchJson, fetchWrapper } from './fetch-wrapper';
export const fetchAllGroups = async (): Promise<Group[]> => {
return (await fetchJson('./api/group/groups', {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as Group[];
};
export const fetchAllUsersForGroups = async (): Promise<User[]> => {
return (await fetchJson('./api/group/users', {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as User[];
};
export const fetchAllMembers = async (groupId: string): Promise<Member[]> => {
return (await fetchJson(`./api/group/members/${groupId}`, {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as Member[];
};
export const fetchGroup = async (groupId: string): Promise<Group> => {
return (await fetchJson(`./api/group/data/${groupId}`, {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as Group;
};
export const fetchGroupRights = async (groupId: string): Promise<string[]> => {
return (await fetchJson(`./api/group/permissions/${groupId}`, {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as string[];
};
export const fetchGroupCategoryRestrictions = async (groupId: string): Promise<CategoryRestrictions> => {
return (await fetchJson(`./api/group/category-restrictions/${groupId}`, {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as CategoryRestrictions;
};
export const saveGroupCategoryRestrictions = async (
groupId: string,
rightId: string,
categoryIds: number[],
csrfToken: string
): Promise<Response> => {
return await fetchWrapper('./api/group/category-restrictions', {
method: 'POST',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ groupId: parseInt(groupId), rightId: parseInt(rightId), categoryIds, csrfToken }),
redirect: 'follow',
referrerPolicy: 'no-referrer',
});
};
export const fetchCategoriesForRestrictions = async (): Promise<CategoryItem[]> => {
return (await fetchJson('./api/group/categories', {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
})) as CategoryItem[];
};