mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-03 08:28:54 -04:00

This was done to give better typings to the function signatures of entities `create` methods. It also ensures that each field that should be set to `null` is set to `null` and doesn't leave that up to the typeorm handlers. See: #1641 Signed-off-by: Philip Molares <philip.molares@udo.edu>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import { Column, Entity, ManyToOne, UpdateDateColumn } from 'typeorm';
|
|
|
|
import { Note } from '../notes/note.entity';
|
|
import { User } from '../users/user.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;
|
|
|
|
/**
|
|
* Create a history entry
|
|
* @param user the user the history entry is associated with
|
|
* @param note the note the history entry is associated with
|
|
* @param [pinStatus=false] if the history entry should be pinned
|
|
*/
|
|
public static create(
|
|
user: User,
|
|
note: Note,
|
|
pinStatus = false,
|
|
): Omit<HistoryEntry, 'updatedAt'> {
|
|
const newHistoryEntry = new HistoryEntry();
|
|
newHistoryEntry.user = user;
|
|
newHistoryEntry.note = note;
|
|
newHistoryEntry.pinStatus = pinStatus;
|
|
return newHistoryEntry;
|
|
}
|
|
}
|