Refactor validations
This commit is contained in:
@@ -21,7 +21,6 @@ import {
|
||||
Length as SimpleLength,
|
||||
} from "sequelize-typescript";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { MAX_TITLE_LENGTH } from "@shared/constants";
|
||||
import { sortNavigationNodes } from "@shared/utils/collections";
|
||||
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { CollectionValidation } from "@shared/validations";
|
||||
@@ -144,8 +143,8 @@ class Collection extends ParanoidModel {
|
||||
|
||||
@NotContainsUrl
|
||||
@Length({
|
||||
max: MAX_TITLE_LENGTH,
|
||||
msg: `name must be ${MAX_TITLE_LENGTH} characters or less`,
|
||||
max: CollectionValidation.maxNameLength,
|
||||
msg: `name must be ${CollectionValidation.maxNameLength} characters or less`,
|
||||
})
|
||||
@Column
|
||||
name: string;
|
||||
|
||||
@@ -35,12 +35,12 @@ import {
|
||||
import MarkdownSerializer from "slate-md-serializer";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import * as Y from "yjs";
|
||||
import { MAX_TITLE_LENGTH } from "@shared/constants";
|
||||
import { DateFilter } from "@shared/types";
|
||||
import getTasks from "@shared/utils/getTasks";
|
||||
import parseTitle from "@shared/utils/parseTitle";
|
||||
import unescape from "@shared/utils/unescape";
|
||||
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { DocumentValidation } from "@shared/validations";
|
||||
import { parser } from "@server/editor";
|
||||
import slugify from "@server/utils/slugify";
|
||||
import Backlink from "./Backlink";
|
||||
@@ -196,8 +196,8 @@ class Document extends ParanoidModel {
|
||||
urlId: string;
|
||||
|
||||
@Length({
|
||||
max: MAX_TITLE_LENGTH,
|
||||
msg: `Document title must be ${MAX_TITLE_LENGTH} characters or less`,
|
||||
max: DocumentValidation.maxTitleLength,
|
||||
msg: `Document title must be ${DocumentValidation.maxTitleLength} characters or less`,
|
||||
})
|
||||
@Column
|
||||
title: string;
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
Length as SimpleLength,
|
||||
} from "sequelize-typescript";
|
||||
import MarkdownSerializer from "slate-md-serializer";
|
||||
import { MAX_TITLE_LENGTH } from "@shared/constants";
|
||||
import { DocumentValidation } from "@shared/validations";
|
||||
import Document from "./Document";
|
||||
import User from "./User";
|
||||
import IdModel from "./base/IdModel";
|
||||
@@ -43,8 +43,8 @@ class Revision extends IdModel {
|
||||
editorVersion: string;
|
||||
|
||||
@Length({
|
||||
max: MAX_TITLE_LENGTH,
|
||||
msg: `Revision title must be ${MAX_TITLE_LENGTH} characters or less`,
|
||||
max: DocumentValidation.maxTitleLength,
|
||||
msg: `Revision title must be ${DocumentValidation.maxTitleLength} characters or less`,
|
||||
})
|
||||
@Column
|
||||
title: string;
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
BeforeValidate,
|
||||
BeforeCreate,
|
||||
} from "sequelize-typescript";
|
||||
import { MAX_TEAM_DOMAINS } from "@shared/constants";
|
||||
import { TeamValidation } from "@shared/validations";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import Team from "./Team";
|
||||
import User from "./User";
|
||||
@@ -59,9 +59,9 @@ class TeamDomain extends IdModel {
|
||||
const count = await this.count({
|
||||
where: { teamId: model.teamId },
|
||||
});
|
||||
if (count >= MAX_TEAM_DOMAINS) {
|
||||
if (count >= TeamValidation.maxDomains) {
|
||||
throw ValidationError(
|
||||
`You have reached the limit of ${MAX_TEAM_DOMAINS} domains`
|
||||
`You have reached the limit of ${TeamValidation.maxDomains} domains`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user