mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
feat: move title and description to revision entity
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
20197d36df
commit
90df9a4e32
8 changed files with 73 additions and 29 deletions
|
@ -7,8 +7,6 @@ import {
|
||||||
Column,
|
Column,
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
JoinTable,
|
|
||||||
ManyToMany,
|
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
|
@ -21,7 +19,6 @@ 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 { Alias } from './alias.entity';
|
import { Alias } from './alias.entity';
|
||||||
import { Tag } from './tag.entity';
|
|
||||||
import { generatePublicId } from './utils';
|
import { generatePublicId } from './utils';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
@ -74,22 +71,6 @@ export class Note {
|
||||||
@OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.note)
|
@OneToMany((_) => MediaUpload, (mediaUpload) => mediaUpload.note)
|
||||||
mediaUploads: Promise<MediaUpload[]>;
|
mediaUploads: Promise<MediaUpload[]>;
|
||||||
|
|
||||||
@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<Tag[]>;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
default: 2,
|
default: 2,
|
||||||
})
|
})
|
||||||
|
@ -122,9 +103,6 @@ export class Note {
|
||||||
newNote.revisions = Promise.resolve([]);
|
newNote.revisions = Promise.resolve([]);
|
||||||
newNote.historyEntries = Promise.resolve([]);
|
newNote.historyEntries = Promise.resolve([]);
|
||||||
newNote.mediaUploads = Promise.resolve([]);
|
newNote.mediaUploads = Promise.resolve([]);
|
||||||
newNote.description = null;
|
|
||||||
newNote.title = null;
|
|
||||||
newNote.tags = Promise.resolve([]);
|
|
||||||
newNote.version = 2;
|
newNote.version = 2;
|
||||||
return newNote;
|
return newNote;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
import { Note } from './note.entity';
|
import { Revision } from '../revisions/revision.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Tag {
|
export class Tag {
|
||||||
|
@ -17,6 +17,6 @@ export class Tag {
|
||||||
})
|
})
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@ManyToMany((_) => Note, (note) => note.tags)
|
@ManyToMany((_) => Revision, (revision) => revision.tags)
|
||||||
notes: Promise<Note[]>;
|
revisions: Promise<Revision[]>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
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 { BaseDto } from '../utils/base.dto.';
|
||||||
import { Revision } from './revision.entity';
|
import { Revision } from './revision.entity';
|
||||||
|
@ -50,4 +50,31 @@ export class RevisionMetadataDto extends BaseDto {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
anonymousAuthorCount: number;
|
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[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
|
import { Tag } from '../notes/tag.entity';
|
||||||
import { Edit } from './edit.entity';
|
import { Edit } from './edit.entity';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +35,23 @@ export class Revision {
|
||||||
})
|
})
|
||||||
patch: string;
|
patch: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
type: 'text',
|
||||||
|
})
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
type: 'text',
|
||||||
|
})
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
@ManyToMany((_) => Tag, (tag) => tag.revisions, {
|
||||||
|
eager: true,
|
||||||
|
cascade: true,
|
||||||
|
})
|
||||||
|
@JoinTable()
|
||||||
|
tags: Promise<Tag[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The note content at this revision.
|
* The note content at this revision.
|
||||||
*/
|
*/
|
||||||
|
@ -77,12 +95,18 @@ export class Revision {
|
||||||
content: string,
|
content: string,
|
||||||
patch: string,
|
patch: string,
|
||||||
note: Note,
|
note: Note,
|
||||||
yjsStateVector?: number[],
|
yjsStateVector: number[] | null,
|
||||||
|
title: string,
|
||||||
|
description: string,
|
||||||
|
tags: Tag[],
|
||||||
): Omit<Revision, 'id' | 'createdAt'> {
|
): Omit<Revision, 'id' | 'createdAt'> {
|
||||||
const newRevision = new Revision();
|
const newRevision = new Revision();
|
||||||
newRevision.patch = patch;
|
newRevision.patch = patch;
|
||||||
newRevision.content = content;
|
newRevision.content = content;
|
||||||
newRevision.length = content.length;
|
newRevision.length = content.length;
|
||||||
|
newRevision.title = title;
|
||||||
|
newRevision.description = description;
|
||||||
|
newRevision.tags = Promise.resolve(tags);
|
||||||
newRevision.note = Promise.resolve(note);
|
newRevision.note = Promise.resolve(note);
|
||||||
newRevision.edits = Promise.resolve([]);
|
newRevision.edits = Promise.resolve([]);
|
||||||
newRevision.yjsStateVector = yjsStateVector ?? null;
|
newRevision.yjsStateVector = yjsStateVector ?? null;
|
||||||
|
|
|
@ -17,4 +17,7 @@ export interface RevisionMetadata {
|
||||||
length: number
|
length: number
|
||||||
authorUsernames: string[]
|
authorUsernames: string[]
|
||||||
anonymousAuthorCount: number
|
anonymousAuthorCount: number
|
||||||
|
title: string
|
||||||
|
tags: string[]
|
||||||
|
description: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => {
|
||||||
respondToMatchingRequest<RevisionDetails>(HttpMethod.GET, req, res, {
|
respondToMatchingRequest<RevisionDetails>(HttpMethod.GET, req, res, {
|
||||||
id: 0,
|
id: 0,
|
||||||
createdAt: '2021-12-21T16:59:42.000Z',
|
createdAt: '2021-12-21T16:59:42.000Z',
|
||||||
|
title: 'Features',
|
||||||
|
description: 'Many features, such wow!',
|
||||||
|
tags: ['hedgedoc', 'demo', 'react'],
|
||||||
patch: `Index:
|
patch: `Index:
|
||||||
===================================================================
|
===================================================================
|
||||||
---
|
---
|
||||||
|
|
|
@ -11,6 +11,9 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => {
|
||||||
respondToMatchingRequest<RevisionDetails>(HttpMethod.GET, req, res, {
|
respondToMatchingRequest<RevisionDetails>(HttpMethod.GET, req, res, {
|
||||||
id: 1,
|
id: 1,
|
||||||
createdAt: '2021-12-29T17:54:11.000Z',
|
createdAt: '2021-12-29T17:54:11.000Z',
|
||||||
|
title: 'Features',
|
||||||
|
description: 'Many more features, such wow!',
|
||||||
|
tags: ['hedgedoc', 'demo', 'react'],
|
||||||
patch: `Index:
|
patch: `Index:
|
||||||
===================================================================
|
===================================================================
|
||||||
---
|
---
|
||||||
|
|
|
@ -14,14 +14,20 @@ const handler = (req: NextApiRequest, res: NextApiResponse): void => {
|
||||||
createdAt: '2021-12-29T17:54:11.000Z',
|
createdAt: '2021-12-29T17:54:11.000Z',
|
||||||
length: 2788,
|
length: 2788,
|
||||||
authorUsernames: [],
|
authorUsernames: [],
|
||||||
anonymousAuthorCount: 4
|
anonymousAuthorCount: 4,
|
||||||
|
title: 'Features',
|
||||||
|
description: 'Many features, such wow!',
|
||||||
|
tags: ['hedgedoc', 'demo', 'react']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 0,
|
||||||
createdAt: '2021-12-21T16:59:42.000Z',
|
createdAt: '2021-12-21T16:59:42.000Z',
|
||||||
length: 2782,
|
length: 2782,
|
||||||
authorUsernames: [],
|
authorUsernames: [],
|
||||||
anonymousAuthorCount: 2
|
anonymousAuthorCount: 2,
|
||||||
|
title: 'Features',
|
||||||
|
description: 'Many more features, such wow!',
|
||||||
|
tags: ['hedgedoc', 'demo', 'react']
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue