mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-02 16:01:55 +00: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
8c050b3c2f
commit
39410ab9c8
1 changed files with 12 additions and 8 deletions
|
@ -59,14 +59,18 @@ export class Note {
|
|||
)
|
||||
authorColors: AuthorColor[];
|
||||
|
||||
constructor(shortid: string, alias: string, owner: User) {
|
||||
if (shortid) {
|
||||
this.shortid = shortid;
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
this.shortid = shortIdGenerate() as string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
public static create(owner?: User, alias?: string, shortid?: string) {
|
||||
if (!shortid) {
|
||||
shortid = shortIdGenerate();
|
||||
}
|
||||
this.alias = alias;
|
||||
this.owner = owner;
|
||||
const newNote = new Note();
|
||||
newNote.shortid = shortid;
|
||||
newNote.alias = alias;
|
||||
newNote.viewcount = 0;
|
||||
newNote.owner = owner;
|
||||
return newNote;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue