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

46 lines
934 B
JavaScript
Raw Normal View History

2022-12-31 16:08:42 -06:00
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);
}
}
2022-11-12 16:20:42 -06:00
2023-01-01 21:09:02 -06:00
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 }) {
2023-01-01 21:09:02 -06:00
const post = new PostContent(content);
post.citations = citations.map((citation) => Citation.fromJSON(citation));
post.id = id;
return post;
}
}