Files
outline/server/models/GroupUser.ts
T
Tom Moor 3886c179c5 Remove default user scope on GroupUser (#11531)
* Remove default user scope on GroupUser

* revert
2026-02-23 20:24:22 -05:00

70 lines
1.3 KiB
TypeScript

import type { InferAttributes, InferCreationAttributes } from "sequelize";
import {
BelongsTo,
ForeignKey,
Column,
Table,
DataType,
Scopes,
} from "sequelize-typescript";
import { GroupPermission } from "@shared/types";
import Group from "./Group";
import User from "./User";
import Model from "./base/Model";
import Fix from "./decorators/Fix";
@Scopes(() => ({
withGroup: {
include: [
{
association: "group",
},
],
},
withUser: {
include: [
{
association: "user",
},
],
},
}))
@Table({ tableName: "group_users", modelName: "group_user" })
@Fix
class GroupUser extends Model<
InferAttributes<GroupUser>,
Partial<InferCreationAttributes<GroupUser>>
> {
static eventNamespace = "groups";
@BelongsTo(() => User, "userId")
user: User;
@ForeignKey(() => User)
@Column(DataType.UUID)
userId: string;
@BelongsTo(() => Group, "groupId")
group: Group;
@ForeignKey(() => Group)
@Column(DataType.UUID)
groupId: string;
@BelongsTo(() => User, "createdById")
createdBy: User;
@ForeignKey(() => User)
@Column(DataType.UUID)
createdById: string;
@Column(DataType.ENUM(...Object.values(GroupPermission)))
permission: GroupPermission;
get modelId() {
return this.groupId;
}
}
export default GroupUser;