83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
import { IsArray, IsDefined, IsInt, IsNotEmpty, IsNumber, IsObject, IsOptional } from "class-validator";
|
|
import { EsPit } from "../../interfaces/elastic/es-pit.interface";
|
|
import { EsQuery } from "../../interfaces/elastic/es-query.interface"
|
|
|
|
/**
|
|
* List of allowed properties in this DTO
|
|
*/
|
|
const allowedProperties = ['size', 'query', 'pit', 'sort'];
|
|
|
|
/**
|
|
* Elasticsearch query DTO
|
|
*/
|
|
@ApiExtraModels()
|
|
export class EsQueryDto {
|
|
/**
|
|
* Maximum number of elements returned by Elasticsearch
|
|
*/
|
|
@IsOptional()
|
|
@IsDefined()
|
|
@IsNumber()
|
|
@IsInt()
|
|
@ApiPropertyOptional({
|
|
description: 'Maximum number of elements returned by Elasticsearch',
|
|
example: 30
|
|
})
|
|
size?: number;
|
|
|
|
/**
|
|
* The search query object passed to Elasticsearch
|
|
*/
|
|
@IsDefined()
|
|
@IsObject()
|
|
@ApiProperty({
|
|
description: 'Search query object passed to Elasticsearch',
|
|
example: {},
|
|
})
|
|
query: EsQuery;
|
|
|
|
/**
|
|
* Object, that stores PIT ID and time alive
|
|
*/
|
|
@IsOptional()
|
|
@IsObject()
|
|
@ApiPropertyOptional({
|
|
description: 'PIT object',
|
|
example: {}
|
|
})
|
|
pit?: EsPit;
|
|
|
|
/**
|
|
* Sorting info
|
|
*/
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ApiPropertyOptional({
|
|
description: '',
|
|
example: []
|
|
})
|
|
sort?: unknown[];
|
|
|
|
/**
|
|
* Pagination info
|
|
*/
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ApiPropertyOptional({
|
|
description: '',
|
|
example: []
|
|
})
|
|
search_after?: unknown[];
|
|
|
|
/**
|
|
* Constructs an empty object
|
|
*/
|
|
constructor() {
|
|
this.size = 10;
|
|
this.query = undefined;
|
|
this.pit = undefined;
|
|
this.sort = undefined;
|
|
this.search_after = undefined;
|
|
}
|
|
} |