refactor: adapt for typeorm 0.3

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-03-20 22:40:41 +01:00
parent a07b5f54d1
commit c4975e4783
21 changed files with 131 additions and 69 deletions

View file

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Column, Entity, ManyToOne } from 'typeorm';
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
import { Note } from '../notes/note.entity';
import { User } from '../users/user.entity';
@ -17,15 +17,19 @@ export class NoteUserPermission {
* See https://github.com/typeorm/typeorm/issues/6908
*/
@PrimaryColumn()
userId: string;
@ManyToOne((_) => User, {
primary: true,
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
orphanedRowAction: 'delete', // This ensures the whole row is deleted when the Permission stops being referenced
})
user: User;
@PrimaryColumn()
noteId: string;
@ManyToOne((_) => Note, (note) => note.userPermissions, {
primary: true,
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
orphanedRowAction: 'delete', // This ensures the whole row is deleted when the Permission stops being referenced
})