UNPKG

2.31 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { defaultPath } from "../decorators.js";
3import { _SPCollection, spInvokableFactory, _SPInstance, } from "../spqueryable.js";
4import { odataUrlFrom } from "../utils/odata-url-from.js";
5import { body } from "@pnp/queryable";
6import { spDelete, spPost } from "../operations.js";
7let _Comments = class _Comments extends _SPCollection {
8 /**
9 * Adds a new comment to this collection
10 *
11 * @param info Comment information to add
12 */
13 async add(info) {
14 if (typeof info === "string") {
15 info = { text: info };
16 }
17 const d = await spPost(Comments(this, null), body(info));
18 return Object.assign(this.getById(d.id), d);
19 }
20 /**
21 * Gets a comment by id
22 *
23 * @param id Id of the comment to load
24 */
25 getById(id) {
26 return Comment(this).concat(`(${id})`);
27 }
28 /**
29 * Deletes all the comments in this collection
30 */
31 clear() {
32 return spPost(Comments(this, "DeleteAll"));
33 }
34};
35_Comments = __decorate([
36 defaultPath("comments")
37], _Comments);
38export { _Comments };
39export const Comments = spInvokableFactory(_Comments);
40export class _Comment extends _SPInstance {
41 /**
42 * A comment's replies
43 */
44 get replies() {
45 return Replies(this);
46 }
47 /**
48 * Likes the comment as the current user
49 */
50 like() {
51 return spPost(Comment(this, "Like"));
52 }
53 /**
54 * Unlikes the comment as the current user
55 */
56 unlike() {
57 return spPost(Comment(this, "Unlike"));
58 }
59 /**
60 * Deletes this comment
61 */
62 delete() {
63 return spDelete(this);
64 }
65}
66export const Comment = spInvokableFactory(_Comment);
67let _Replies = class _Replies extends _SPCollection {
68 /**
69 * Adds a new reply to this collection
70 *
71 * @param info Comment information to add
72 */
73 async add(info) {
74 if (typeof info === "string") {
75 info = { text: info };
76 }
77 const d = await spPost(Replies(this, null), body(info));
78 return Object.assign(Comment([this, odataUrlFrom(d)]), d);
79 }
80};
81_Replies = __decorate([
82 defaultPath("replies")
83], _Replies);
84export { _Replies };
85export const Replies = spInvokableFactory(_Replies);
86//# sourceMappingURL=types.js.map
\No newline at end of file