@pnp/sp
Version:
pnp - provides a fluent api for working with SharePoint REST
86 lines • 2.31 kB
JavaScript
import { __decorate } from "tslib";
import { defaultPath } from "../decorators.js";
import { _SPCollection, spInvokableFactory, _SPInstance, } from "../spqueryable.js";
import { odataUrlFrom } from "../utils/odata-url-from.js";
import { body } from "@pnp/queryable";
import { spDelete, spPost } from "../operations.js";
let _Comments = class _Comments extends _SPCollection {
/**
* Adds a new comment to this collection
*
* @param info Comment information to add
*/
async add(info) {
if (typeof info === "string") {
info = { text: info };
}
const d = await spPost(Comments(this, null), body(info));
return Object.assign(this.getById(d.id), d);
}
/**
* Gets a comment by id
*
* @param id Id of the comment to load
*/
getById(id) {
return Comment(this).concat(`(${id})`);
}
/**
* Deletes all the comments in this collection
*/
clear() {
return spPost(Comments(this, "DeleteAll"));
}
};
_Comments = __decorate([
defaultPath("comments")
], _Comments);
export { _Comments };
export const Comments = spInvokableFactory(_Comments);
export class _Comment extends _SPInstance {
/**
* A comment's replies
*/
get replies() {
return Replies(this);
}
/**
* Likes the comment as the current user
*/
like() {
return spPost(Comment(this, "Like"));
}
/**
* Unlikes the comment as the current user
*/
unlike() {
return spPost(Comment(this, "Unlike"));
}
/**
* Deletes this comment
*/
delete() {
return spDelete(this);
}
}
export const Comment = spInvokableFactory(_Comment);
let _Replies = class _Replies extends _SPCollection {
/**
* Adds a new reply to this collection
*
* @param info Comment information to add
*/
async add(info) {
if (typeof info === "string") {
info = { text: info };
}
const d = await spPost(Replies(this, null), body(info));
return Object.assign(Comment([this, odataUrlFrom(d)]), d);
}
};
_Replies = __decorate([
defaultPath("replies")
], _Replies);
export { _Replies };
export const Replies = spInvokableFactory(_Replies);
//# sourceMappingURL=types.js.map