diff --git a/src/authors/author.entity.ts b/src/authors/author.entity.ts index c07d0a2b4..a0ffa44d1 100644 --- a/src/authors/author.entity.ts +++ b/src/authors/author.entity.ts @@ -4,14 +4,54 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Entity, PrimaryGeneratedColumn } from 'typeorm'; -import { Note } from '../notes/note.entity'; +import { + Column, + Entity, + ManyToOne, + OneToMany, + PrimaryGeneratedColumn, +} from 'typeorm'; +import { Authorship } from '../revisions/authorship.entity'; +import { Session } from '../users/session.entity'; +import { User } from '../users/user.entity'; +export type AuthorColor = number; + +/** + * The author represents a single user editing a note. + * A 'user' can either be a registered and logged-in user or a browser session identified by its cookie. + * All edits (aka authorships) of one user in a note must belong to the same author, so that the same color can be displayed. + */ @Entity() export class Author { - //TODO: Still missing many properties @PrimaryGeneratedColumn() id: number; - note: Note; + /** + * The id of the color of this author + * The application maps the id to an actual color + */ + @Column({ type: 'int' }) + color: AuthorColor; + + /** + * A list of (browser) sessions this author has + * Only contains sessions for anonymous users, which don't have a user set + */ + @OneToMany(() => Session, (session) => session.author) + sessions: Session[]; + + /** + * User that this author corresponds to + * Only set when the user was identified (by a browser session) as a registered user at edit-time + */ + @ManyToOne(() => User, (user) => user.authors, { nullable: true }) + user: User | null; + + /** + * List of authorships that this author created + * All authorships must belong to the same note + */ + @OneToMany(() => Authorship, (authorship) => authorship.author) + authorships: Authorship[]; }