mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04: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
990742e569
commit
7d5dddaaaf
3 changed files with 46 additions and 3 deletions
|
@ -2,6 +2,8 @@ import { generate as shortIdGenerate } from 'shortid';
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
Entity,
|
Entity,
|
||||||
|
JoinTable,
|
||||||
|
ManyToMany,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
|
@ -11,6 +13,7 @@ import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { Revision } from '../revisions/revision.entity';
|
import { Revision } from '../revisions/revision.entity';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
import { AuthorColor } from './author-color.entity';
|
import { AuthorColor } from './author-color.entity';
|
||||||
|
import { Tag } from './tag.entity';
|
||||||
|
|
||||||
@Entity('Notes')
|
@Entity('Notes')
|
||||||
export class Note {
|
export class Note {
|
||||||
|
@ -25,7 +28,7 @@ export class Note {
|
||||||
unique: true,
|
unique: true,
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
alias: string;
|
alias?: string;
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
_ => NoteGroupPermission,
|
_ => NoteGroupPermission,
|
||||||
groupPermission => groupPermission.note,
|
groupPermission => groupPermission.note,
|
||||||
|
@ -59,10 +62,26 @@ export class Note {
|
||||||
)
|
)
|
||||||
authorColors: AuthorColor[];
|
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
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
|
|
||||||
public static create(owner?: User, alias?: string, shortid?: string) {
|
public static create(owner?: User, alias?: string, shortid?: string): Note {
|
||||||
if (!shortid) {
|
if (!shortid) {
|
||||||
shortid = shortIdGenerate();
|
shortid = shortIdGenerate();
|
||||||
}
|
}
|
||||||
|
@ -74,6 +93,10 @@ export class Note {
|
||||||
newNote.authorColors = [];
|
newNote.authorColors = [];
|
||||||
newNote.userPermissions = [];
|
newNote.userPermissions = [];
|
||||||
newNote.groupPermissions = [];
|
newNote.groupPermissions = [];
|
||||||
|
newNote.revisions = Promise.resolve([]);
|
||||||
|
newNote.description = null;
|
||||||
|
newNote.title = null;
|
||||||
|
newNote.tags = [];
|
||||||
return newNote;
|
return newNote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@ import { UsersModule } from '../users/users.module';
|
||||||
import { AuthorColor } from './author-color.entity';
|
import { AuthorColor } from './author-color.entity';
|
||||||
import { Note } from './note.entity';
|
import { Note } from './note.entity';
|
||||||
import { NotesService } from './notes.service';
|
import { NotesService } from './notes.service';
|
||||||
|
import { Tag } from './tag.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Note, AuthorColor]),
|
TypeOrmModule.forFeature([Note, AuthorColor, Tag]),
|
||||||
forwardRef(() => RevisionsModule),
|
forwardRef(() => RevisionsModule),
|
||||||
UsersModule,
|
UsersModule,
|
||||||
LoggerModule,
|
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…
Add table
Add a link
Reference in a new issue