From ea4de0dfb593b3f2a64d76958859e9ce030f29cb Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 5 Oct 2023 22:32:58 -0400 Subject: [PATCH] chore: Docs, define additional client-side relations --- app/models/Pin.ts | 16 +++++++++++++++- app/models/Revision.ts | 8 ++++++-- app/models/Share.ts | 13 +++++++++---- app/models/Star.ts | 24 +++++++++++++++++++++--- app/models/Subscription.ts | 22 ++++++++++++++-------- app/models/View.ts | 2 ++ 6 files changed, 67 insertions(+), 18 deletions(-) diff --git a/app/models/Pin.ts b/app/models/Pin.ts index 5543100d5..5a4082ace 100644 --- a/app/models/Pin.ts +++ b/app/models/Pin.ts @@ -1,12 +1,26 @@ import { observable } from "mobx"; +import Collection from "./Collection"; +import Document from "./Document"; import Model from "./base/Model"; import Field from "./decorators/Field"; +import Relation from "./decorators/Relation"; class Pin extends Model { - id: string; + /** The collection ID that the document is pinned to. If empty the document is pinned to home. */ collectionId: string; + + /** The collection that the document is pinned to. If empty the document is pinned to home. */ + @Relation(() => Collection, { onDelete: "cascade" }) + collection?: Collection; + + /** The document ID that is pinned. */ documentId: string; + /** The document that is pinned. */ + @Relation(() => Document, { onDelete: "cascade" }) + document: Document; + + /** The sort order of the pin on screen. */ @observable @Field index: string; diff --git a/app/models/Revision.ts b/app/models/Revision.ts index b449b523c..da157883c 100644 --- a/app/models/Revision.ts +++ b/app/models/Revision.ts @@ -1,14 +1,18 @@ import { computed } from "mobx"; import { isRTL } from "@shared/utils/rtl"; +import Document from "./Document"; import User from "./User"; import Model from "./base/Model"; import Relation from "./decorators/Relation"; class Revision extends Model { - id: string; - + /** The document ID that the revision is related to */ documentId: string; + /** The document that the revision is related to */ + @Relation(() => Document, { onDelete: "cascade" }) + document: Document; + /** The document title when the revision was created */ title: string; diff --git a/app/models/Share.ts b/app/models/Share.ts index d52ac44c6..ea1d7b850 100644 --- a/app/models/Share.ts +++ b/app/models/Share.ts @@ -1,13 +1,11 @@ import { observable } from "mobx"; +import Document from "./Document"; import User from "./User"; import Model from "./base/Model"; import Field from "./decorators/Field"; +import Relation from "./decorators/Relation"; class Share extends Model { - @Field - @observable - id: string; - @Field @observable published: boolean; @@ -16,10 +14,15 @@ class Share extends Model { @observable includeChildDocuments: boolean; + /** The document ID that is shared. */ @Field @observable documentId: string; + /** The document that is shared. */ + @Relation(() => Document, { onDelete: "cascade" }) + document: Document; + @Field @observable urlId: string; @@ -36,6 +39,8 @@ class Share extends Model { @observable url: string; + /** The user that shared the document. */ + @Relation(() => User, { onDelete: "null" }) createdBy: User; } diff --git a/app/models/Star.ts b/app/models/Star.ts index b5c43ab80..4d9f83df5 100644 --- a/app/models/Star.ts +++ b/app/models/Star.ts @@ -1,26 +1,44 @@ import { observable } from "mobx"; import type StarsStore from "~/stores/StarsStore"; +import Collection from "./Collection"; +import Document from "./Document"; import Model from "./base/Model"; import Field from "./decorators/Field"; +import Relation from "./decorators/Relation"; class Star extends Model { - id: string; - + /** The sort order of the star */ @Field @observable index: string; - documentId: string; + /** The document ID that is starred. */ + documentId?: string; + /** The document that is starred. */ + @Relation(() => Document, { onDelete: "cascade" }) + document?: Document; + + /** The collection ID that is starred. */ collectionId: string; + /** The collection that is starred. */ + @Relation(() => Collection, { onDelete: "cascade" }) + collection: Collection; + store: StarsStore; + /** + * Returns the next star in the list, or undefined if this is the last star. + */ next(): Star | undefined { const index = this.store.orderedData.indexOf(this); return this.store.orderedData[index + 1]; } + /** + * Returns the previous star in the list, or undefined if this is the first star. + */ previous(): Star | undefined { const index = this.store.orderedData.indexOf(this); return this.store.orderedData[index + 1]; diff --git a/app/models/Subscription.ts b/app/models/Subscription.ts index 1321e067a..0f9627c61 100644 --- a/app/models/Subscription.ts +++ b/app/models/Subscription.ts @@ -1,22 +1,28 @@ import { observable } from "mobx"; +import Document from "./Document"; +import User from "./User"; import Model from "./base/Model"; import Field from "./decorators/Field"; +import Relation from "./decorators/Relation"; /** - * A subscription represents a request for a user to receive notifications for - * a document. + * A subscription represents a request for a user to receive notifications for a document. */ class Subscription extends Model { - @Field - @observable - id: string; - - /** The user subscribing */ + /** The user ID subscribing */ userId: string; - /** The document being subscribed to */ + /** The user subscribing */ + @Relation(() => User, { onDelete: "cascade" }) + user?: User; + + /** The document ID being subscribed to */ documentId: string; + /** The document being subscribed to */ + @Relation(() => Document, { onDelete: "cascade" }) + document?: Document; + /** The event being subscribed to */ @Field @observable diff --git a/app/models/View.ts b/app/models/View.ts index dd045a42e..a10890f44 100644 --- a/app/models/View.ts +++ b/app/models/View.ts @@ -1,6 +1,7 @@ import { action, observable } from "mobx"; import User from "./User"; import Model from "./base/Model"; +import Relation from "./decorators/Relation"; class View extends Model { id: string; @@ -15,6 +16,7 @@ class View extends Model { @observable count: number; + @Relation(() => User) user: User; @action