mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-19 10:43:57 +00:00
Add note metadata properties and Tag entity.
These were planned to be parsed at runtime from the note-content in the database, but having to run a markdown parser in the backend was found to be a bad idea. Now the frontend (that already implements the parsing logic) has to set title, description and tags. Signed-off-by: David Mehren <git@herrmehren.de> Co-authored-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
b9dfd880f7
commit
f1f57eca54
3 changed files with 46 additions and 3 deletions
|
@ -2,6 +2,8 @@ import { generate as shortIdGenerate } from 'shortid';
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinTable,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
|
@ -11,6 +13,7 @@ import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
|||
import { Revision } from '../revisions/revision.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { AuthorColor } from './author-color.entity';
|
||||
import { Tag } from './tag.entity';
|
||||
|
||||
@Entity('Notes')
|
||||
export class Note {
|
||||
|
@ -25,7 +28,7 @@ export class Note {
|
|||
unique: true,
|
||||
nullable: true,
|
||||
})
|
||||
alias: string;
|
||||
alias?: string;
|
||||
@OneToMany(
|
||||
_ => NoteGroupPermission,
|
||||
groupPermission => groupPermission.note,
|
||||
|
@ -59,10 +62,26 @@ export class Note {
|
|||
)
|
||||
authorColors: AuthorColor[];
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
description?: string;
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
title?: string;
|
||||
|
||||
@ManyToMany(
|
||||
_ => Tag,
|
||||
tag => tag.notes,
|
||||
)
|
||||
@JoinTable()
|
||||
tags: Tag[];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
public static create(owner?: User, alias?: string, shortid?: string) {
|
||||
public static create(owner?: User, alias?: string, shortid?: string): Note {
|
||||
if (!shortid) {
|
||||
shortid = shortIdGenerate();
|
||||
}
|
||||
|
@ -74,6 +93,10 @@ export class Note {
|
|||
newNote.authorColors = [];
|
||||
newNote.userPermissions = [];
|
||||
newNote.groupPermissions = [];
|
||||
newNote.revisions = Promise.resolve([]);
|
||||
newNote.description = null;
|
||||
newNote.title = null;
|
||||
newNote.tags = [];
|
||||
return newNote;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ import { UsersModule } from '../users/users.module';
|
|||
import { AuthorColor } from './author-color.entity';
|
||||
import { Note } from './note.entity';
|
||||
import { NotesService } from './notes.service';
|
||||
import { Tag } from './tag.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Note, AuthorColor]),
|
||||
TypeOrmModule.forFeature([Note, AuthorColor, Tag]),
|
||||
forwardRef(() => RevisionsModule),
|
||||
UsersModule,
|
||||
LoggerModule,
|
||||
|
|
19
src/notes/tag.entity.ts
Normal file
19
src/notes/tag.entity.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Note } from './note.entity';
|
||||
|
||||
@Entity()
|
||||
export class Tag {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@ManyToMany(
|
||||
_ => Note,
|
||||
note => note.tags,
|
||||
)
|
||||
notes: Note[];
|
||||
}
|
Loading…
Reference in a new issue