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:
David Mehren 2020-09-19 16:00:29 +02:00
parent bb9e60d5f6
commit 2261b81139
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -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;
} }
} }