mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 14:00:56 -05:00
History: Add HistoryEntry
With this the backend now can hold a history entry. Also included in this commit are some minor changes to tests and services so they can still work. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
2ee8ff4d91
commit
300b464efd
7 changed files with 72 additions and 2 deletions
|
@ -134,11 +134,20 @@ entity "media_upload" {
|
|||
*createdAt : date
|
||||
}
|
||||
|
||||
entity "history_entry" {
|
||||
*noteId : uuid <<FK note>>
|
||||
*userId : uuid <<FK user>>
|
||||
--
|
||||
*pinStatus: boolean
|
||||
*updatedAt: date
|
||||
}
|
||||
|
||||
user "1" -- "0..*" note: owner
|
||||
user "1" -u- "1..*" identity
|
||||
user "1" - "1..*" auth_token: authTokens
|
||||
user "1" -l- "1..*" session
|
||||
user "1" - "0..*" media_upload
|
||||
user "1" - "0..*" history_entry
|
||||
user "0..*" -- "0..*" note
|
||||
user "1" - "0..*" authorship
|
||||
|
||||
|
@ -149,6 +158,7 @@ revision "0..*" - "0..*" authorship
|
|||
|
||||
media_upload "0..*" -- "1" note
|
||||
note "1" - "1..*" revision
|
||||
note "1" - "0..*" history_entry
|
||||
note "0..*" -l- "0..*" tag
|
||||
note "0..*" -- "0..*" group
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import { Identity } from '../../../users/identity.entity';
|
|||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
import { MeController } from './me.controller';
|
||||
import { HistoryEntry } from '../../../history/history-entry.entity';
|
||||
|
||||
describe('Me Controller', () => {
|
||||
let controller: MeController;
|
||||
|
@ -44,6 +45,8 @@ describe('Me Controller', () => {
|
|||
.useValue({})
|
||||
.overrideProvider(getRepositoryToken(Tag))
|
||||
.useValue({})
|
||||
.overrideProvider(getRepositoryToken(HistoryEntry))
|
||||
.useValue({})
|
||||
.compile();
|
||||
|
||||
controller = module.get<MeController>(MeController);
|
||||
|
|
|
@ -28,6 +28,7 @@ describe('AuthService', () => {
|
|||
id: '1',
|
||||
identities: [],
|
||||
ownedNotes: [],
|
||||
historyEntries: [],
|
||||
updatedAt: new Date(),
|
||||
userName: 'Testy',
|
||||
};
|
||||
|
|
47
src/history/history-entry.entity.ts
Normal file
47
src/history/history-entry.entity.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '../users/user.entity';
|
||||
import { Note } from '../notes/note.entity';
|
||||
|
||||
@Entity()
|
||||
export class HistoryEntry {
|
||||
@ManyToOne((_) => User, (user) => user.historyEntries, {
|
||||
onDelete: 'CASCADE',
|
||||
primary: true,
|
||||
})
|
||||
user: User;
|
||||
|
||||
@ManyToOne((_) => Note, (note) => note.historyEntries, {
|
||||
onDelete: 'CASCADE',
|
||||
primary: true,
|
||||
})
|
||||
note: Note;
|
||||
|
||||
@Column()
|
||||
pinStatus: boolean;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
|
||||
// The optional note parameter is necessary for the createNote method in the NotesService,
|
||||
// as we create the note then and don't need to add it to the HistoryEntry.
|
||||
public static create(user: User, note?: Note): HistoryEntry {
|
||||
const newHistoryEntry = new HistoryEntry();
|
||||
newHistoryEntry.user = user;
|
||||
if (note) {
|
||||
newHistoryEntry.note = note;
|
||||
}
|
||||
newHistoryEntry.pinStatus = false;
|
||||
return newHistoryEntry;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ import { Revision } from '../revisions/revision.entity';
|
|||
import { User } from '../users/user.entity';
|
||||
import { AuthorColor } from './author-color.entity';
|
||||
import { Tag } from './tag.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
|
||||
@Entity()
|
||||
export class Note {
|
||||
|
@ -53,6 +54,8 @@ export class Note {
|
|||
revisions: Promise<Revision[]>;
|
||||
@OneToMany((_) => AuthorColor, (authorColor) => authorColor.note)
|
||||
authorColors: AuthorColor[];
|
||||
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
|
||||
historyEntries: HistoryEntry[];
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
|
|
|
@ -21,6 +21,7 @@ import {
|
|||
import { NoteDto } from './note.dto';
|
||||
import { Note } from './note.entity';
|
||||
import { Tag } from './tag.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
|
||||
@Injectable()
|
||||
export class NotesService {
|
||||
|
@ -46,6 +47,7 @@ export class NotesService {
|
|||
description: 'Very descriptive text.',
|
||||
userPermissions: [],
|
||||
groupPermissions: [],
|
||||
historyEntries: [],
|
||||
tags: [],
|
||||
revisions: Promise.resolve([]),
|
||||
authorColors: [],
|
||||
|
@ -69,6 +71,7 @@ export class NotesService {
|
|||
newNote.alias = alias;
|
||||
}
|
||||
if (owner) {
|
||||
newNote.historyEntries = [HistoryEntry.create(owner)];
|
||||
newNote.owner = owner;
|
||||
}
|
||||
return this.noteRepository.save(newNote);
|
||||
|
@ -153,12 +156,14 @@ export class NotesService {
|
|||
id: '1',
|
||||
identities: [],
|
||||
ownedNotes: [],
|
||||
historyEntries: [],
|
||||
updatedAt: new Date(),
|
||||
userName: 'Testy',
|
||||
},
|
||||
description: 'Very descriptive text.',
|
||||
userPermissions: [],
|
||||
groupPermissions: [],
|
||||
historyEntries: [],
|
||||
tags: [],
|
||||
revisions: Promise.resolve([]),
|
||||
authorColors: [],
|
||||
|
|
|
@ -14,6 +14,7 @@ import { Column, OneToMany } from 'typeorm';
|
|||
import { Note } from '../notes/note.entity';
|
||||
import { AuthToken } from '../auth/auth-token.entity';
|
||||
import { Identity } from './identity.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
|
@ -51,8 +52,8 @@ export class User {
|
|||
@OneToMany((_) => Identity, (identity) => identity.user)
|
||||
identities: Identity[];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
|
||||
historyEntries: HistoryEntry[];
|
||||
|
||||
public static create(
|
||||
userName: string,
|
||||
|
|
Loading…
Reference in a new issue