From 90df9a4e324b5a1090d8277432644f7d80bcb217 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Sun, 11 Jun 2023 12:48:30 +0200 Subject: [PATCH] feat: move title and description to revision entity Signed-off-by: Tilman Vatteroth --- backend/src/notes/note.entity.ts | 22 -------------- backend/src/notes/tag.entity.ts | 6 ++-- .../src/revisions/revision-metadata.dto.ts | 29 ++++++++++++++++++- backend/src/revisions/revision.entity.ts | 26 ++++++++++++++++- frontend/src/api/revisions/types.ts | 3 ++ .../api/private/notes/features/revisions/0.ts | 3 ++ .../api/private/notes/features/revisions/1.ts | 3 ++ .../private/notes/features/revisions/index.ts | 10 +++++-- 8 files changed, 73 insertions(+), 29 deletions(-) diff --git a/backend/src/notes/note.entity.ts b/backend/src/notes/note.entity.ts index 6f8c79f94..5f69bb3a4 100644 --- a/backend/src/notes/note.entity.ts +++ b/backend/src/notes/note.entity.ts @@ -7,8 +7,6 @@ import { Column, CreateDateColumn, Entity, - JoinTable, - ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn, @@ -21,7 +19,6 @@ 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'; @Entity() @@ -74,22 +71,6 @@ export class Note { @OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.note) mediaUploads: Promise; - @Column({ - nullable: true, - type: 'text', - }) - description: string | null; - - @Column({ - nullable: true, - type: 'text', - }) - title: string | null; - - @ManyToMany((_) => Tag, (tag) => tag.notes, { eager: true, cascade: true }) - @JoinTable() - tags: Promise; - @Column({ default: 2, }) @@ -122,9 +103,6 @@ export class Note { newNote.revisions = Promise.resolve([]); newNote.historyEntries = Promise.resolve([]); newNote.mediaUploads = Promise.resolve([]); - newNote.description = null; - newNote.title = null; - newNote.tags = Promise.resolve([]); newNote.version = 2; return newNote; } diff --git a/backend/src/notes/tag.entity.ts b/backend/src/notes/tag.entity.ts index f054cdca5..8907100d1 100644 --- a/backend/src/notes/tag.entity.ts +++ b/backend/src/notes/tag.entity.ts @@ -5,7 +5,7 @@ */ import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm'; -import { Note } from './note.entity'; +import { Revision } from '../revisions/revision.entity'; @Entity() export class Tag { @@ -17,6 +17,6 @@ export class Tag { }) name: string; - @ManyToMany((_) => Note, (note) => note.tags) - notes: Promise; + @ManyToMany((_) => Revision, (revision) => revision.tags) + revisions: Promise; } diff --git a/backend/src/revisions/revision-metadata.dto.ts b/backend/src/revisions/revision-metadata.dto.ts index e3a39fc67..19b5a0f2f 100644 --- a/backend/src/revisions/revision-metadata.dto.ts +++ b/backend/src/revisions/revision-metadata.dto.ts @@ -5,7 +5,7 @@ */ import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; -import { IsDate, IsNumber, IsString } from 'class-validator'; +import { IsArray, IsDate, IsNumber, IsString } from 'class-validator'; import { BaseDto } from '../utils/base.dto.'; import { Revision } from './revision.entity'; @@ -50,4 +50,31 @@ export class RevisionMetadataDto extends BaseDto { @IsNumber() @ApiProperty() anonymousAuthorCount: number; + + /** + * Title of the note + * Does not contain any markup but might be empty + * @example "Shopping List" + */ + @IsString() + @ApiProperty() + title: string; + + /** + * Description of the note + * Does not contain any markup but might be empty + * @example Everything I want to buy + */ + @IsString() + @ApiProperty() + description: string; + + /** + * List of tags assigned to this note + * @example "['shopping', 'personal'] + */ + @IsArray() + @IsString({ each: true }) + @ApiProperty() + tags: string[]; } diff --git a/backend/src/revisions/revision.entity.ts b/backend/src/revisions/revision.entity.ts index 8607c34bc..cdd770220 100644 --- a/backend/src/revisions/revision.entity.ts +++ b/backend/src/revisions/revision.entity.ts @@ -14,6 +14,7 @@ import { } from 'typeorm'; import { Note } from '../notes/note.entity'; +import { Tag } from '../notes/tag.entity'; import { Edit } from './edit.entity'; /** @@ -34,6 +35,23 @@ export class Revision { }) patch: string; + @Column({ + type: 'text', + }) + title: string; + + @Column({ + type: 'text', + }) + description: string; + + @ManyToMany((_) => Tag, (tag) => tag.revisions, { + eager: true, + cascade: true, + }) + @JoinTable() + tags: Promise; + /** * The note content at this revision. */ @@ -77,12 +95,18 @@ export class Revision { content: string, patch: string, note: Note, - yjsStateVector?: number[], + yjsStateVector: number[] | null, + title: string, + description: string, + tags: Tag[], ): Omit { const newRevision = new Revision(); newRevision.patch = patch; newRevision.content = content; newRevision.length = content.length; + newRevision.title = title; + newRevision.description = description; + newRevision.tags = Promise.resolve(tags); newRevision.note = Promise.resolve(note); newRevision.edits = Promise.resolve([]); newRevision.yjsStateVector = yjsStateVector ?? null; diff --git a/frontend/src/api/revisions/types.ts b/frontend/src/api/revisions/types.ts index 0be666033..11840596e 100644 --- a/frontend/src/api/revisions/types.ts +++ b/frontend/src/api/revisions/types.ts @@ -17,4 +17,7 @@ export interface RevisionMetadata { length: number authorUsernames: string[] anonymousAuthorCount: number + title: string + tags: string[] + description: string } diff --git a/frontend/src/pages/api/private/notes/features/revisions/0.ts b/frontend/src/pages/api/private/notes/features/revisions/0.ts index 601140a5b..dc39264e6 100644 --- a/frontend/src/pages/api/private/notes/features/revisions/0.ts +++ b/frontend/src/pages/api/private/notes/features/revisions/0.ts @@ -11,6 +11,9 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => { respondToMatchingRequest(HttpMethod.GET, req, res, { id: 0, createdAt: '2021-12-21T16:59:42.000Z', + title: 'Features', + description: 'Many features, such wow!', + tags: ['hedgedoc', 'demo', 'react'], patch: `Index: =================================================================== --- diff --git a/frontend/src/pages/api/private/notes/features/revisions/1.ts b/frontend/src/pages/api/private/notes/features/revisions/1.ts index 63eb41d38..b5a955260 100644 --- a/frontend/src/pages/api/private/notes/features/revisions/1.ts +++ b/frontend/src/pages/api/private/notes/features/revisions/1.ts @@ -11,6 +11,9 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => { respondToMatchingRequest(HttpMethod.GET, req, res, { id: 1, createdAt: '2021-12-29T17:54:11.000Z', + title: 'Features', + description: 'Many more features, such wow!', + tags: ['hedgedoc', 'demo', 'react'], patch: `Index: =================================================================== --- diff --git a/frontend/src/pages/api/private/notes/features/revisions/index.ts b/frontend/src/pages/api/private/notes/features/revisions/index.ts index d9e72553f..5cef755b7 100644 --- a/frontend/src/pages/api/private/notes/features/revisions/index.ts +++ b/frontend/src/pages/api/private/notes/features/revisions/index.ts @@ -14,14 +14,20 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => { createdAt: '2021-12-29T17:54:11.000Z', length: 2788, authorUsernames: [], - anonymousAuthorCount: 4 + anonymousAuthorCount: 4, + title: 'Features', + description: 'Many features, such wow!', + tags: ['hedgedoc', 'demo', 'react'] }, { id: 0, createdAt: '2021-12-21T16:59:42.000Z', length: 2782, authorUsernames: [], - anonymousAuthorCount: 2 + anonymousAuthorCount: 2, + title: 'Features', + description: 'Many more features, such wow!', + tags: ['hedgedoc', 'demo', 'react'] } ]) }