Refactor validations

This commit is contained in:
Tom Moor
2022-07-24 13:40:04 +01:00
parent 870d9ed41e
commit ec35af4bc5
13 changed files with 47 additions and 33 deletions

View File

@@ -5,8 +5,8 @@ import mammoth from "mammoth";
import quotedPrintable from "quoted-printable";
import { Transaction } from "sequelize";
import utf8 from "utf8";
import { MAX_TITLE_LENGTH } from "@shared/constants";
import parseTitle from "@shared/utils/parseTitle";
import { DocumentValidation } from "@shared/validations";
import { APM } from "@server/logging/tracing";
import { User } from "@server/models";
import dataURItoBuffer from "@server/utils/dataURItoBuffer";
@@ -221,7 +221,7 @@ async function documentImporter({
}
// It's better to truncate particularly long titles than fail the import
title = truncate(title, { length: MAX_TITLE_LENGTH });
title = truncate(title, { length: DocumentValidation.maxTitleLength });
return {
text,

View File

@@ -1,11 +1,10 @@
import fractionalIndex from "fractional-index";
import { Sequelize, Op, WhereOptions } from "sequelize";
import { PinValidation } from "@shared/validations";
import { sequelize } from "@server/database/sequelize";
import { ValidationError } from "@server/errors";
import { Pin, User, Event } from "@server/models";
const MAX_PINS = 8;
type Props = {
/** The user creating the pin */
user: User;
@@ -40,8 +39,10 @@ export default async function pinCreator({
};
const count = await Pin.count({ where });
if (count >= MAX_PINS) {
throw ValidationError(`You cannot pin more than ${MAX_PINS} documents`);
if (count >= PinValidation.max) {
throw ValidationError(
`You cannot pin more than ${PinValidation.max} documents`
);
}
if (!index) {