MCPcopy Create free account
hub / github.com/clintonwoo/hackernews-react-graphql / CommentModel

Class CommentModel

src/data/models/comment-model.ts:1–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1export class CommentModel {
2 public readonly id: number;
3
4 public readonly creationTime: number;
5
6 public readonly comments: number[];
7
8 public readonly parent: number;
9
10 public readonly submitterId: string;
11
12 public readonly upvotes: string[];
13
14 public readonly text: string;
15
16 constructor(fields) {
17 if (!fields.id) {
18 throw new Error(`Error instantiating Comment, id invalid: ${fields.id}`);
19 } else if (!fields.parent) {
20 throw new Error(`Error instantiating Comment, parent invalid: ${fields.parent}`);
21 } else if (!fields.submitterId) {
22 throw new Error(`Error instantiating Comment, submitterId invalid: ${fields.submitterId}`);
23 } else if (!fields.text) {
24 throw new Error(`Error instantiating Comment, text invalid: ${fields.text}`);
25 }
26
27 this.id = fields.id;
28 this.creationTime = fields.creationTime || +new Date();
29 this.comments = fields.comments || [];
30 this.parent = fields.parent;
31 this.submitterId = fields.submitterId;
32 this.text = fields.text;
33 this.upvotes = fields.upvotes || [];
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected