* fix: type server models * fix: make ParanoidModel generic * fix: ApiKey * fix: Attachment * fix: AuthenticationProvider * fix: Backlink * fix: Collection * fix: Comment * fix: Document * fix: FileOperation * fix: Group * fix: GroupPermission * fix: GroupUser * fix: Integration * fix: IntegrationAuthentication * fix: Notification * fix: Pin * fix: Revision * fix: SearchQuery * fix: Share * fix: Star * fix: Subscription * fix: TypeError * fix: Imports * fix: Team * fix: TeamDomain * fix: User * fix: UserAuthentication * fix: UserPermission * fix: View * fix: WebhookDelivery * fix: WebhookSubscription * Remove type duplication --------- Co-authored-by: Tom Moor <tom.moor@gmail.com>
84 lines
1.7 KiB
TypeScript
84 lines
1.7 KiB
TypeScript
import { InferAttributes, InferCreationAttributes, Op } from "sequelize";
|
|
import {
|
|
BelongsTo,
|
|
Column,
|
|
Default,
|
|
ForeignKey,
|
|
IsIn,
|
|
Table,
|
|
DataType,
|
|
Scopes,
|
|
} from "sequelize-typescript";
|
|
import { CollectionPermission } from "@shared/types";
|
|
import Collection from "./Collection";
|
|
import Document from "./Document";
|
|
import Group from "./Group";
|
|
import User from "./User";
|
|
import ParanoidModel from "./base/ParanoidModel";
|
|
import Fix from "./decorators/Fix";
|
|
|
|
@Scopes(() => ({
|
|
withGroup: {
|
|
include: [
|
|
{
|
|
association: "group",
|
|
},
|
|
],
|
|
},
|
|
withCollection: {
|
|
where: {
|
|
collectionId: {
|
|
[Op.ne]: null,
|
|
},
|
|
},
|
|
include: [
|
|
{
|
|
association: "collection",
|
|
},
|
|
],
|
|
},
|
|
}))
|
|
@Table({ tableName: "group_permissions", modelName: "group_permission" })
|
|
@Fix
|
|
class GroupPermission extends ParanoidModel<
|
|
InferAttributes<GroupPermission>,
|
|
Partial<InferCreationAttributes<GroupPermission>>
|
|
> {
|
|
@Default(CollectionPermission.ReadWrite)
|
|
@IsIn([Object.values(CollectionPermission)])
|
|
@Column(DataType.STRING)
|
|
permission: CollectionPermission;
|
|
|
|
// associations
|
|
|
|
@BelongsTo(() => Collection, "collectionId")
|
|
collection?: Collection | null;
|
|
|
|
@ForeignKey(() => Collection)
|
|
@Column(DataType.UUID)
|
|
collectionId?: string | null;
|
|
|
|
@BelongsTo(() => Document, "documentId")
|
|
document?: Document | null;
|
|
|
|
@ForeignKey(() => Document)
|
|
@Column(DataType.UUID)
|
|
documentId?: string | null;
|
|
|
|
@BelongsTo(() => Group, "groupId")
|
|
group: Group;
|
|
|
|
@ForeignKey(() => Group)
|
|
@Column(DataType.UUID)
|
|
groupId: string;
|
|
|
|
@BelongsTo(() => User, "createdById")
|
|
createdBy: User;
|
|
|
|
@ForeignKey(() => User)
|
|
@Column(DataType.UUID)
|
|
createdById: string;
|
|
}
|
|
|
|
export default GroupPermission;
|