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 8c050b3c2f
commit 39410ab9c8
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

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