@pnp/sp
Version:
pnp - provides a fluent api for working with SharePoint REST
85 lines • 2.57 kB
JavaScript
import { __decorate } from "tslib";
import { _SPCollection, spInvokableFactory, _SPInstance, } from "../spqueryable.js";
import { SiteUsers } from "../site-users/types.js";
import { body } from "@pnp/queryable";
import { defaultPath } from "../decorators.js";
import { spPost, spPostMerge } from "../operations.js";
let _SiteGroups = class _SiteGroups extends _SPCollection {
/**
* Gets a group from the collection by id
*
* @param id The id of the group to retrieve
*/
getById(id) {
return SiteGroup(this).concat(`(${id})`);
}
/**
* Adds a new group to the site collection
*
* @param properties The group properties object of property names and values to be set for the group
*/
async add(properties) {
const data = await spPost(this, body(properties));
return {
data,
group: this.getById(data.Id),
};
}
/**
* Gets a group from the collection by name
*
* @param groupName The name of the group to retrieve
*/
getByName(groupName) {
return SiteGroup(this, `getByName('${groupName}')`);
}
/**
* Removes the group with the specified member id from the collection
*
* @param id The id of the group to remove
*/
removeById(id) {
return spPost(SiteGroups(this, `removeById('${id}')`));
}
/**
* Removes the cross-site group with the specified name from the collection
*
* @param loginName The name of the group to remove
*/
removeByLoginName(loginName) {
return spPost(SiteGroups(this, `removeByLoginName('${loginName}')`));
}
};
_SiteGroups = __decorate([
defaultPath("sitegroups")
], _SiteGroups);
export { _SiteGroups };
export const SiteGroups = spInvokableFactory(_SiteGroups);
export class _SiteGroup extends _SPInstance {
/**
* Gets the users for this group
*
*/
get users() {
return SiteUsers(this, "users");
}
/**
* @param props Group properties to update
*/
async update(props) {
const data = await spPostMerge(this, body(props));
return {
data,
group: this,
};
}
/**
* Set the owner of a group using a user id
* @param userId the id of the user that will be set as the owner of the current group
*/
setUserAsOwner(userId) {
return spPost(SiteGroup(this, `SetUserAsOwner(${userId})`));
}
}
export const SiteGroup = spInvokableFactory(_SiteGroup);
//# sourceMappingURL=types.js.map