UNPKG

1.95 kBJavaScriptView Raw
1import { addProp } from "@pnp/queryable";
2import { _Item, Item } from "../items/types.js";
3import { Comments } from "./types.js";
4import { spPost } from "../operations.js";
5import { extractWebUrl } from "../utils/extract-web-url.js";
6import { combine } from "@pnp/core";
7import { SPQueryable } from "../spqueryable.js";
8addProp(_Item, "comments", Comments);
9_Item.prototype.getLikedBy = function () {
10 return spPost(Item(this, "likedBy"));
11};
12_Item.prototype.like = async function () {
13 const itemInfo = await this.getParentInfos();
14 const baseUrl = extractWebUrl(this.toUrl());
15 const reputationUrl = "_api/Microsoft.Office.Server.ReputationModel.Reputation.SetLike(listID=@a1,itemID=@a2,like=@a3)";
16 const likeUrl = combine(baseUrl, reputationUrl) + `?@a1='{${itemInfo.ParentList.Id}}'&@a2='${itemInfo.Item.Id}'&@a3=true`;
17 return spPost(SPQueryable([this, likeUrl]));
18};
19_Item.prototype.unlike = async function () {
20 const itemInfo = await this.getParentInfos();
21 const baseUrl = extractWebUrl(this.toUrl());
22 const reputationUrl = "_api/Microsoft.Office.Server.ReputationModel.Reputation.SetLike(listID=@a1,itemID=@a2,like=@a3)";
23 const likeUrl = combine(baseUrl, reputationUrl) + `?@a1='{${itemInfo.ParentList.Id}}'&@a2='${itemInfo.Item.Id}'&@a3=false`;
24 return spPost(SPQueryable([this, likeUrl]));
25};
26_Item.prototype.getLikedByInformation = function () {
27 return Item(this, "likedByInformation").expand("likedby")();
28};
29_Item.prototype.rate = async function (value) {
30 const itemInfo = await this.getParentInfos();
31 const baseUrl = extractWebUrl(this.toUrl());
32 const reputationUrl = "_api/Microsoft.Office.Server.ReputationModel.Reputation.SetRating(listID=@a1,itemID=@a2,rating=@a3)";
33 const rateUrl = combine(baseUrl, reputationUrl) + `?@a1='{${itemInfo.ParentList.Id}}'&@a2='${itemInfo.Item.Id}'&@a3=${value}`;
34 return spPost(SPQueryable([this, rateUrl]));
35};
36//# sourceMappingURL=item.js.map
\No newline at end of file