-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-snippet-dto.ts
49 lines (42 loc) · 1.14 KB
/
update-snippet-dto.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Snippet, SnippetVisibility } from '@sharingan/database';
type Input = {
content: string;
contentHighlighted: string;
creatorId: string;
description: string | null;
language: string;
lineHighlight: string | null;
name: string;
snippetId: string;
theme: string;
visibility: SnippetVisibility;
};
export default class UpdateSnippetDto {
constructor(private _input: Input) {}
get name(): string {
return this._input.name;
}
get snippetId(): string {
return this._input.snippetId;
}
get creatorId(): string {
return this._input.creatorId;
}
toSnippet(currentSnippet: Snippet): Snippet {
return {
...currentSnippet,
content: this._input.content,
contentHtml: this._input.contentHighlighted,
description: this._input.description,
language: this._input.language,
lineHighlight: this._input.lineHighlight,
name: this._input.name,
size: this.getContentSize(),
theme: this._input.theme,
visibility: this._input.visibility,
};
}
private getContentSize(): number {
return new TextEncoder().encode(this._input.content).buffer.byteLength;
}
}