feat: Document subscriptions (#3834)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
committed by
GitHub
parent
864f585e5b
commit
24c71c38a5
@@ -794,10 +794,27 @@ class Document extends ParanoidModel {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a list of users that have collaborated on this document
|
||||
*
|
||||
* @param options FindOptions
|
||||
* @returns A promise that resolve to a list of users
|
||||
*/
|
||||
collaborators = async (options?: FindOptions<User>): Promise<User[]> => {
|
||||
const users = await Promise.all(
|
||||
this.collaboratorIds.map((collaboratorId) =>
|
||||
User.findByPk(collaboratorId, options)
|
||||
)
|
||||
);
|
||||
|
||||
return compact(users);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate all of the document ids that are children of this document by
|
||||
* iterating through parentDocumentId references in the most efficient way.
|
||||
*
|
||||
* @param where query options to further filter the documents
|
||||
* @param options FindOptions
|
||||
* @returns A promise that resolves to a list of document ids
|
||||
*/
|
||||
|
||||
@@ -11,12 +11,22 @@ import {
|
||||
IsIn,
|
||||
Default,
|
||||
DataType,
|
||||
Scopes,
|
||||
} from "sequelize-typescript";
|
||||
import env from "@server/env";
|
||||
import Team from "./Team";
|
||||
import User from "./User";
|
||||
import Fix from "./decorators/Fix";
|
||||
|
||||
@Scopes(() => ({
|
||||
withUser: {
|
||||
include: [
|
||||
{
|
||||
association: "user",
|
||||
},
|
||||
],
|
||||
},
|
||||
}))
|
||||
@Table({
|
||||
tableName: "notification_settings",
|
||||
modelName: "notification_setting",
|
||||
|
||||
46
server/models/Subscription.ts
Normal file
46
server/models/Subscription.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {
|
||||
Column,
|
||||
DataType,
|
||||
BelongsTo,
|
||||
ForeignKey,
|
||||
Table,
|
||||
IsIn,
|
||||
Scopes,
|
||||
} from "sequelize-typescript";
|
||||
import Document from "./Document";
|
||||
import User from "./User";
|
||||
import ParanoidModel from "./base/ParanoidModel";
|
||||
import Fix from "./decorators/Fix";
|
||||
|
||||
@Scopes(() => ({
|
||||
withUser: {
|
||||
include: [
|
||||
{
|
||||
association: "user",
|
||||
},
|
||||
],
|
||||
},
|
||||
}))
|
||||
@Table({ tableName: "subscriptions", modelName: "subscription" })
|
||||
@Fix
|
||||
class Subscription extends ParanoidModel {
|
||||
@BelongsTo(() => User, "userId")
|
||||
user: User;
|
||||
|
||||
@ForeignKey(() => User)
|
||||
@Column(DataType.UUID)
|
||||
userId: string;
|
||||
|
||||
@BelongsTo(() => Document, "documentId")
|
||||
document: Document | null;
|
||||
|
||||
@ForeignKey(() => Document)
|
||||
@Column(DataType.UUID)
|
||||
documentId: string | null;
|
||||
|
||||
@IsIn([["documents.update"]])
|
||||
@Column(DataType.STRING)
|
||||
event: string;
|
||||
}
|
||||
|
||||
export default Subscription;
|
||||
@@ -53,3 +53,5 @@ export { default as View } from "./View";
|
||||
export { default as WebhookSubscription } from "./WebhookSubscription";
|
||||
|
||||
export { default as WebhookDelivery } from "./WebhookDelivery";
|
||||
|
||||
export { default as Subscription } from "./Subscription";
|
||||
|
||||
Reference in New Issue
Block a user