UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

35 lines 1.92 kB
import { addProp } from "@pnp/queryable"; import { _Item, Item } from "../items/types.js"; import { Comments } from "./types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine } from "@pnp/core"; import { SPQueryable, spPost } from "../spqueryable.js"; addProp(_Item, "comments", Comments); _Item.prototype.getLikedBy = function () { return spPost(Item(this, "likedBy")); }; _Item.prototype.like = async function () { const itemInfo = await this.getParentInfos(); const baseUrl = extractWebUrl(this.toUrl()); const reputationUrl = "_api/Microsoft.Office.Server.ReputationModel.Reputation.SetLike(listID=@a1,itemID=@a2,like=@a3)"; const likeUrl = combine(baseUrl, reputationUrl) + `?@a1='{${itemInfo.ParentList.Id}}'&@a2='${itemInfo.Item.Id}'&@a3=true`; return spPost(SPQueryable([this, likeUrl])); }; _Item.prototype.unlike = async function () { const itemInfo = await this.getParentInfos(); const baseUrl = extractWebUrl(this.toUrl()); const reputationUrl = "_api/Microsoft.Office.Server.ReputationModel.Reputation.SetLike(listID=@a1,itemID=@a2,like=@a3)"; const likeUrl = combine(baseUrl, reputationUrl) + `?@a1='{${itemInfo.ParentList.Id}}'&@a2='${itemInfo.Item.Id}'&@a3=false`; return spPost(SPQueryable([this, likeUrl])); }; _Item.prototype.getLikedByInformation = function () { return Item(this, "likedByInformation").expand("likedby")(); }; _Item.prototype.rate = async function (value) { const itemInfo = await this.getParentInfos(); const baseUrl = extractWebUrl(this.toUrl()); const reputationUrl = "_api/Microsoft.Office.Server.ReputationModel.Reputation.SetRating(listID=@a1,itemID=@a2,rating=@a3)"; const rateUrl = combine(baseUrl, reputationUrl) + `?@a1='{${itemInfo.ParentList.Id}}'&@a2='${itemInfo.Item.Id}'&@a3=${value}`; return spPost(SPQueryable([this, rateUrl])); }; //# sourceMappingURL=item.js.map