Type server models (#6326)
* 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>
This commit is contained in:
@@ -3,7 +3,13 @@ import compact from "lodash/compact";
|
||||
import isNil from "lodash/isNil";
|
||||
import uniq from "lodash/uniq";
|
||||
import randomstring from "randomstring";
|
||||
import type { Identifier, NonNullFindOptions, SaveOptions } from "sequelize";
|
||||
import type {
|
||||
Identifier,
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
NonNullFindOptions,
|
||||
SaveOptions,
|
||||
} from "sequelize";
|
||||
import {
|
||||
Sequelize,
|
||||
Transaction,
|
||||
@@ -186,7 +192,10 @@ type AdditionalFindOptions = {
|
||||
}))
|
||||
@Table({ tableName: "documents", modelName: "document" })
|
||||
@Fix
|
||||
class Document extends ParanoidModel {
|
||||
class Document extends ParanoidModel<
|
||||
InferAttributes<Document>,
|
||||
Partial<InferCreationAttributes<Document>>
|
||||
> {
|
||||
@SimpleLength({
|
||||
min: 10,
|
||||
max: 10,
|
||||
@@ -208,7 +217,7 @@ class Document extends ParanoidModel {
|
||||
|
||||
@IsNumeric
|
||||
@Column(DataType.SMALLINT)
|
||||
version: number;
|
||||
version?: number | null;
|
||||
|
||||
@Default(false)
|
||||
@Column
|
||||
@@ -261,7 +270,7 @@ class Document extends ParanoidModel {
|
||||
msg: `Document collaborative state is too large, you must create a new document`,
|
||||
})
|
||||
@Column(DataType.BLOB)
|
||||
state: Uint8Array;
|
||||
state?: Uint8Array | null;
|
||||
|
||||
/** Whether this document is part of onboarding. */
|
||||
@Default(false)
|
||||
@@ -387,14 +396,13 @@ class Document extends ParanoidModel {
|
||||
// ensure documents have a title
|
||||
model.title = model.title || "";
|
||||
|
||||
if (model.previous("title") && model.previous("title") !== model.title) {
|
||||
const previousTitle = model.previous("title");
|
||||
if (previousTitle && previousTitle !== model.title) {
|
||||
if (!model.previousTitles) {
|
||||
model.previousTitles = [];
|
||||
}
|
||||
|
||||
model.previousTitles = uniq(
|
||||
model.previousTitles.concat(model.previous("title"))
|
||||
);
|
||||
model.previousTitles = uniq(model.previousTitles.concat(previousTitle));
|
||||
}
|
||||
|
||||
// add the current user as a collaborator on this doc
|
||||
|
||||
Reference in New Issue
Block a user