UNPKG

2.57 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { _SPCollection, spInvokableFactory, _SPInstance, } from "../spqueryable.js";
3import { SiteUsers } from "../site-users/types.js";
4import { body } from "@pnp/queryable";
5import { defaultPath } from "../decorators.js";
6import { spPost, spPostMerge } from "../operations.js";
7let _SiteGroups = class _SiteGroups extends _SPCollection {
8 /**
9 * Gets a group from the collection by id
10 *
11 * @param id The id of the group to retrieve
12 */
13 getById(id) {
14 return SiteGroup(this).concat(`(${id})`);
15 }
16 /**
17 * Adds a new group to the site collection
18 *
19 * @param properties The group properties object of property names and values to be set for the group
20 */
21 async add(properties) {
22 const data = await spPost(this, body(properties));
23 return {
24 data,
25 group: this.getById(data.Id),
26 };
27 }
28 /**
29 * Gets a group from the collection by name
30 *
31 * @param groupName The name of the group to retrieve
32 */
33 getByName(groupName) {
34 return SiteGroup(this, `getByName('${groupName}')`);
35 }
36 /**
37 * Removes the group with the specified member id from the collection
38 *
39 * @param id The id of the group to remove
40 */
41 removeById(id) {
42 return spPost(SiteGroups(this, `removeById('${id}')`));
43 }
44 /**
45 * Removes the cross-site group with the specified name from the collection
46 *
47 * @param loginName The name of the group to remove
48 */
49 removeByLoginName(loginName) {
50 return spPost(SiteGroups(this, `removeByLoginName('${loginName}')`));
51 }
52};
53_SiteGroups = __decorate([
54 defaultPath("sitegroups")
55], _SiteGroups);
56export { _SiteGroups };
57export const SiteGroups = spInvokableFactory(_SiteGroups);
58export class _SiteGroup extends _SPInstance {
59 /**
60 * Gets the users for this group
61 *
62 */
63 get users() {
64 return SiteUsers(this, "users");
65 }
66 /**
67 * @param props Group properties to update
68 */
69 async update(props) {
70 const data = await spPostMerge(this, body(props));
71 return {
72 data,
73 group: this,
74 };
75 }
76 /**
77 * Set the owner of a group using a user id
78 * @param userId the id of the user that will be set as the owner of the current group
79 */
80 setUserAsOwner(userId) {
81 return spPost(SiteGroup(this, `SetUserAsOwner(${userId})`));
82 }
83}
84export const SiteGroup = spInvokableFactory(_SiteGroup);
85//# sourceMappingURL=types.js.map
\No newline at end of file