From 2fa1e8cf17352f7244c36cb51f29a0969768a1d4 Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Mon, 8 Mar 2021 12:19:27 +0100 Subject: [PATCH] Change imports for @class-validator --- src/scripts/classes/query/latest-search-query.ts | 12 ++++++------ src/scripts/classes/query/thread-search-query.ts | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/scripts/classes/query/latest-search-query.ts b/src/scripts/classes/query/latest-search-query.ts index a93e2e8..d6d61aa 100644 --- a/src/scripts/classes/query/latest-search-query.ts +++ b/src/scripts/classes/query/latest-search-query.ts @@ -6,7 +6,7 @@ "use strict"; // Public modules from npm -import validator from "class-validator"; +import { ArrayMaxSize, IsInt, Min, validateSync } from "class-validator"; // Modules from file import { urls } from "../../constants/url.js"; @@ -49,16 +49,16 @@ export default class LatestSearchQuery implements IQuery { */ public date: TDate = null; - @validator.ArrayMaxSize(LatestSearchQuery.MAX_TAGS, { + @ArrayMaxSize(LatestSearchQuery.MAX_TAGS, { message: "Too many tags: $value instead of $constraint1" }) public includedTags: string[] = []; public includedPrefixes: string[] = []; - @validator.IsInt({ + @IsInt({ message: "$property expect an integer, received $value" }) - @validator.Min(LatestSearchQuery.MIN_PAGE, { + @Min(LatestSearchQuery.MIN_PAGE, { message: "The minimum $property value must be $constraint1, received $value" }) public page = LatestSearchQuery.MIN_PAGE; @@ -69,13 +69,13 @@ export default class LatestSearchQuery implements IQuery { //#region Public methods public validate(): boolean { - return validator.validateSync(this).length === 0; + return validateSync(this).length === 0; } public async execute(): Promise>> { // Check if the query is valid if (!this.validate()) { - throw new Error(`Invalid query: ${validator.validateSync(this).join("\n")}`); + throw new Error(`Invalid query: ${validateSync(this).join("\n")}`); } // Prepare the URL diff --git a/src/scripts/classes/query/thread-search-query.ts b/src/scripts/classes/query/thread-search-query.ts index 6b9e801..6f1d83d 100644 --- a/src/scripts/classes/query/thread-search-query.ts +++ b/src/scripts/classes/query/thread-search-query.ts @@ -6,7 +6,7 @@ "use strict"; // Public modules from npm -import validator from "class-validator"; +import { IsInt, Min, validateSync } from "class-validator"; // Module from files import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js"; @@ -61,10 +61,10 @@ export default class ThreadSearchQuery implements IQuery { * Results presentation order. */ public order: TThreadOrder = "relevance"; - @validator.IsInt({ + @IsInt({ message: "$property expect an integer, received $value" }) - @validator.Min(ThreadSearchQuery.MIN_PAGE, { + @Min(ThreadSearchQuery.MIN_PAGE, { message: "The minimum $property value must be $constraint1, received $value" }) public page = 1; @@ -75,13 +75,13 @@ export default class ThreadSearchQuery implements IQuery { //#region Public methods public validate(): boolean { - return validator.validateSync(this).length === 0; + return validateSync(this).length === 0; } public async execute(): Promise>> { // Check if the query is valid if (!this.validate()) { - throw new Error(`Invalid query: ${validator.validateSync(this).join("\n")}`); + throw new Error(`Invalid query: ${validateSync(this).join("\n")}`); } // Define the POST parameters