feat: add list of aliases to note entity

One of the aliases can be primary for each note, but all can be used to get information from the apis.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-06-06 17:46:32 +02:00 committed by David Mehren
parent 86d060706f
commit 17c55195c3
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
6 changed files with 115 additions and 13 deletions

View file

@ -19,6 +19,7 @@ import { NoteGroupPermission } from '../permissions/note-group-permission.entity
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
import { Revision } from '../revisions/revision.entity';
import { User } from '../users/user.entity';
import { Alias } from './alias.entity';
import { Tag } from './tag.entity';
import { generatePublicId } from './utils';
@ -28,12 +29,12 @@ export class Note {
id: string;
@Column({ type: 'text' })
publicId: string;
@Column({
unique: true,
nullable: true,
type: 'text',
})
alias: string | null;
@OneToMany(
(_) => Alias,
(alias) => alias.note,
{ cascade: true }, // This ensures that embedded Aliases are automatically saved to the database
)
aliases: Alias[];
@OneToMany(
(_) => NoteGroupPermission,
(groupPermission) => groupPermission.note,
@ -84,7 +85,7 @@ export class Note {
public static create(owner?: User, alias?: string): Note {
const newNote = new Note();
newNote.publicId = generatePublicId();
newNote.alias = alias ?? null;
newNote.aliases = alias ? [Alias.create(alias, true)] : [];
newNote.viewCount = 0;
newNote.owner = owner ?? null;
newNote.userPermissions = [];