forked from aaronmars/martian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpageComment.js
More file actions
31 lines (30 loc) · 1.45 KB
/
pageComment.js
File metadata and controls
31 lines (30 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Plug } from '/mindtouch-http.js/plug.js';
import { Settings } from './lib/settings.js';
import { modelParser } from './lib/modelParser.js';
import { utility } from './lib/utility.js';
import { pageCommentModel } from './models/pageCommentModel.js';
export class PageComment {
constructor(pageId = 'home', commentId, settings = new Settings()) {
if(!commentId) {
throw new Error('The PageComment must be constructed with a comment ID.');
}
this._plug = new Plug(settings.host, settings.plugConfig).at('@api', 'deki', 'pages', utility.getResourceId(pageId, 'home'), 'comments', commentId);
}
update(newComment) {
return this._plug.at('content').put(newComment, utility.textRequestType).then((r) => r.json()).then(modelParser.createParser(pageCommentModel));
}
delete() {
return this._plug.delete();
}
}
export class PageCommentManager {
constructor(pageId = 'home', settings = new Settings()) {
this._plug = new Plug(settings.host, settings.plugConfig).at('@api', 'deki', 'pages', utility.getResourceId(pageId, 'home'), 'comments');
}
addComment(comment, title = '') {
if(!comment) {
return Promise.reject(new Error('The comment text must be supplied, and must not be empty.'));
}
return this._plug.withParam('title', title).post(comment, utility.textRequestType).then((r) => r.json()).then(modelParser.createParser(pageCommentModel));
}
}