Change imports for @class-validator
parent
a4be89c5fc
commit
2fa1e8cf17
|
@ -6,7 +6,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Public modules from npm
|
// Public modules from npm
|
||||||
import validator from "class-validator";
|
import { ArrayMaxSize, IsInt, Min, validateSync } from "class-validator";
|
||||||
|
|
||||||
// Modules from file
|
// Modules from file
|
||||||
import { urls } from "../../constants/url.js";
|
import { urls } from "../../constants/url.js";
|
||||||
|
@ -49,16 +49,16 @@ export default class LatestSearchQuery implements IQuery {
|
||||||
*/
|
*/
|
||||||
public date: TDate = null;
|
public date: TDate = null;
|
||||||
|
|
||||||
@validator.ArrayMaxSize(LatestSearchQuery.MAX_TAGS, {
|
@ArrayMaxSize(LatestSearchQuery.MAX_TAGS, {
|
||||||
message: "Too many tags: $value instead of $constraint1"
|
message: "Too many tags: $value instead of $constraint1"
|
||||||
})
|
})
|
||||||
public includedTags: string[] = [];
|
public includedTags: string[] = [];
|
||||||
public includedPrefixes: string[] = [];
|
public includedPrefixes: string[] = [];
|
||||||
|
|
||||||
@validator.IsInt({
|
@IsInt({
|
||||||
message: "$property expect an integer, received $value"
|
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"
|
message: "The minimum $property value must be $constraint1, received $value"
|
||||||
})
|
})
|
||||||
public page = LatestSearchQuery.MIN_PAGE;
|
public page = LatestSearchQuery.MIN_PAGE;
|
||||||
|
@ -69,13 +69,13 @@ export default class LatestSearchQuery implements IQuery {
|
||||||
//#region Public methods
|
//#region Public methods
|
||||||
|
|
||||||
public validate(): boolean {
|
public validate(): boolean {
|
||||||
return validator.validateSync(this).length === 0;
|
return validateSync(this).length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(): Promise<Result<GenericAxiosError, AxiosResponse<any>>> {
|
public async execute(): Promise<Result<GenericAxiosError, AxiosResponse<any>>> {
|
||||||
// Check if the query is valid
|
// Check if the query is valid
|
||||||
if (!this.validate()) {
|
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
|
// Prepare the URL
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Public modules from npm
|
// Public modules from npm
|
||||||
import validator from "class-validator";
|
import { IsInt, Min, validateSync } from "class-validator";
|
||||||
|
|
||||||
// Module from files
|
// Module from files
|
||||||
import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js";
|
import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js";
|
||||||
|
@ -61,10 +61,10 @@ export default class ThreadSearchQuery implements IQuery {
|
||||||
* Results presentation order.
|
* Results presentation order.
|
||||||
*/
|
*/
|
||||||
public order: TThreadOrder = "relevance";
|
public order: TThreadOrder = "relevance";
|
||||||
@validator.IsInt({
|
@IsInt({
|
||||||
message: "$property expect an integer, received $value"
|
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"
|
message: "The minimum $property value must be $constraint1, received $value"
|
||||||
})
|
})
|
||||||
public page = 1;
|
public page = 1;
|
||||||
|
@ -75,13 +75,13 @@ export default class ThreadSearchQuery implements IQuery {
|
||||||
//#region Public methods
|
//#region Public methods
|
||||||
|
|
||||||
public validate(): boolean {
|
public validate(): boolean {
|
||||||
return validator.validateSync(this).length === 0;
|
return validateSync(this).length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(): Promise<Result<GenericAxiosError, AxiosResponse<any>>> {
|
public async execute(): Promise<Result<GenericAxiosError, AxiosResponse<any>>> {
|
||||||
// Check if the query is valid
|
// Check if the query is valid
|
||||||
if (!this.validate()) {
|
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
|
// Define the POST parameters
|
||||||
|
|
Loading…
Reference in New Issue