diff --git a/server/models/Document.ts b/server/models/Document.ts index 2829be2bf4..efe2aa1308 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -64,7 +64,7 @@ import Team from "./Team"; import User from "./User"; import UserMembership from "./UserMembership"; import View from "./View"; -import ParanoidModel from "./base/ParanoidModel"; +import ArchivableModel from "./base/ArchivableModel"; import Fix from "./decorators/Fix"; import { DocumentHelper } from "./helpers/DocumentHelper"; import IsHexColor from "./validators/IsHexColor"; @@ -259,7 +259,7 @@ type AdditionalFindOptions = { })) @Table({ tableName: "documents", modelName: "document" }) @Fix -class Document extends ParanoidModel< +class Document extends ArchivableModel< InferAttributes, Partial> > { @@ -362,11 +362,6 @@ class Document extends ParanoidModel< @Column(DataType.INTEGER) revisionCount: number; - /** Whether the document is archvied, and if so when. */ - @IsDate - @Column - archivedAt: Date | null; - /** Whether the document is published, and if so when. */ @IsDate @Column diff --git a/server/models/base/ArchivableModel.ts b/server/models/base/ArchivableModel.ts new file mode 100644 index 0000000000..7240dbb9ae --- /dev/null +++ b/server/models/base/ArchivableModel.ts @@ -0,0 +1,25 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import { AllowNull, Column, IsDate } from "sequelize-typescript"; +import ParanoidModel from "./ParanoidModel"; + +class ArchivableModel< + TModelAttributes extends {} = any, + TCreationAttributes extends {} = TModelAttributes +> extends ParanoidModel { + /** Whether the document is archvied, and if so when. */ + @AllowNull + @IsDate + @Column + archivedAt: Date | null; + + /** + * Whether the model has been archived. + * + * @returns True if the model has been archived + */ + get isArchived() { + return !!this.archivedAt; + } +} + +export default ArchivableModel;