1 | import { addProp } from "@pnp/queryable";
|
2 | import { _Item, Item } from "../items/types.js";
|
3 | import { Comments } from "./types.js";
|
4 | import { spPost } from "../operations.js";
|
5 | import { extractWebUrl } from "../utils/extract-web-url.js";
|
6 | import { combine } from "@pnp/core";
|
7 | import { SPQueryable } from "../spqueryable.js";
|
8 | addProp(_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(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(likeUrl));
|
25 | };
|
26 | _Item.prototype.getLikedByInformation = function () {
|
27 | return Item(this, "likedByInformation").expand("likedby")();
|
28 | };
|
29 |
|
\ | No newline at end of file |