import { isUUID } from "class-validator"; import type { Identifier, InferAttributes, InferCreationAttributes, NonNullFindOptions, FindOptions, } from "sequelize"; import { EmptyResultError } from "sequelize"; import { Column, DataType, BelongsTo, ForeignKey, Table, Length as SimpleLength, DefaultScope, Default, HasMany, Unique, Scopes, BeforeValidate, IsDate, } from "sequelize-typescript"; import slugify from "slugify"; import type { ProsemirrorData } from "@shared/types"; import { UrlHelper } from "@shared/utils/UrlHelper"; import { DocumentValidation } from "@shared/validations"; import { generateUrlId } from "@server/utils/url"; import Collection from "./Collection"; import Revision from "./Revision"; import Team from "./Team"; import User from "./User"; import ParanoidModel from "./base/ParanoidModel"; import Fix from "./decorators/Fix"; import IsHexColor from "./validators/IsHexColor"; import Length from "./validators/Length"; type AdditionalFindOptions = { userId?: string; includeState?: boolean; rejectOnEmpty?: boolean | Error; }; @DefaultScope(() => ({ include: [ { association: "createdBy", paranoid: false, }, { association: "updatedBy", paranoid: false, }, ], where: { template: true, }, attributes: { exclude: ["state"], }, })) @Scopes(() => ({ withMembership: (userId: string, paranoid = true) => ({ include: [ { model: userId ? Collection.scope([ "defaultScope", { method: ["withMembership", userId], }, ]) : Collection, as: "collection", paranoid, }, ], }), withCollection: { include: [ { model: Collection, as: "collection", }, ], }, })) @Table({ tableName: "documents", modelName: "template" }) @Fix class Template extends ParanoidModel< InferAttributes