mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
NoteEntity: Move constructor-code to create() method
TypeORM does not like having application code in the constructor (https://github.com/typeorm/typeorm/issues/1772#issuecomment-514787854), therefore that is moved into a new `create() static method. Additionally, the constructor is now `private`, which enforces the use of the new method. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
bb9e60d5f6
commit
2261b81139
1 changed files with 12 additions and 8 deletions
|
@ -59,14 +59,18 @@ export class Note {
|
||||||
)
|
)
|
||||||
authorColors: AuthorColor[];
|
authorColors: AuthorColor[];
|
||||||
|
|
||||||
constructor(shortid: string, alias: string, owner: User) {
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
if (shortid) {
|
private constructor() {}
|
||||||
this.shortid = shortid;
|
|
||||||
} else {
|
public static create(owner?: User, alias?: string, shortid?: string) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
if (!shortid) {
|
||||||
this.shortid = shortIdGenerate() as string;
|
shortid = shortIdGenerate();
|
||||||
}
|
}
|
||||||
this.alias = alias;
|
const newNote = new Note();
|
||||||
this.owner = owner;
|
newNote.shortid = shortid;
|
||||||
|
newNote.alias = alias;
|
||||||
|
newNote.viewcount = 0;
|
||||||
|
newNote.owner = owner;
|
||||||
|
return newNote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue