Refactor validations
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user