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:
Philip Molares 2021-02-03 21:15:39 +01:00
parent 6bce4c241b
commit b76fa91a3c
7 changed files with 72 additions and 2 deletions

View 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;
}
}