mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 16:14:43 -04:00
feat: add list of aliases to note entity
One of the aliases can be primary for each note, but all can be used to get information from the apis. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
86d060706f
commit
17c55195c3
6 changed files with 115 additions and 13 deletions
63
src/notes/alias.entity.ts
Normal file
63
src/notes/alias.entity.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
|
||||
import { Note } from './note.entity';
|
||||
import { PrimaryValueTransformer } from './primary.value-transformer';
|
||||
|
||||
@Entity()
|
||||
@Unique('Only one primary alias per note', ['note', 'primary'])
|
||||
export class Alias {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* the actual alias
|
||||
*/
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
})
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Is this alias the primary alias, by which people access the note?
|
||||
*/
|
||||
@Column({
|
||||
/*
|
||||
Because of the @Unique at the top of this entity, this field must be saved as null instead of false in the DB.
|
||||
If a non-primary alias would be saved with `primary: false` it would only be possible to have one non-primary and one primary alias.
|
||||
But a nullable field does not have such problems.
|
||||
This way the DB keeps track that one note really only has one primary alias.
|
||||
*/
|
||||
comment:
|
||||
'This field tells you if this is the primary alias of the note. If this field is null, that means this alias is not primary.',
|
||||
nullable: true,
|
||||
transformer: new PrimaryValueTransformer(),
|
||||
})
|
||||
primary: boolean;
|
||||
|
||||
@ManyToOne((_) => Note, (note) => note.aliases, {
|
||||
onDelete: 'CASCADE', // This deletes the Alias, when the associated Note is deleted
|
||||
})
|
||||
note: Note;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
static create(name: string, primary = false): Alias {
|
||||
const alias = new Alias();
|
||||
alias.name = name;
|
||||
alias.primary = primary;
|
||||
return alias;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue