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