dao-governance-framework/forum-network/public/classes/post.js

46 lines
934 B
JavaScript

export class Citation {
constructor(postId, weight) {
this.postId = postId;
this.weight = weight;
}
toJSON() {
return {
postId: this.postId,
weight: this.weight,
};
}
static fromJSON({ postId, weight }) {
return new Citation(postId, weight);
}
}
export class PostContent {
constructor(content) {
this.content = content;
this.citations = [];
}
addCitation(postId, weight) {
const citation = new Citation(postId, weight);
this.citations.push(citation);
return this;
}
toJSON() {
return {
content: this.content,
citations: this.citations.map((citation) => citation.toJSON()),
...(this.id ? { id: this.id } : {}),
};
}
static fromJSON({ id, content, citations }) {
const post = new PostContent(content);
post.citations = citations.map((citation) => Citation.fromJSON(citation));
post.id = id;
return post;
}
}