Minor code cleanup.

This commit is contained in:
danny-mhlv 2022-08-16 19:22:27 +03:00
parent a645498658
commit 569ef08f1f
18 changed files with 66 additions and 60 deletions

View File

@ -1,5 +1,5 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger";
import { IsArray, IsDefined, IsIn, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { IsNotEmpty, IsOptional } from "class-validator";
import { PaperDto } from "./paper.dto"; import { PaperDto } from "./paper.dto";
/** /**

View File

@ -1,3 +1,8 @@
export * from './es-response.dto' export * from './es-query.dto';
export * from './page.dto' export * from './es-response.dto';
export * from './search-q.dto' export * from './es-hit.dto';
export * from './page.dto';
export * from './search-q.dto';
export * from './search-result.dto';
export * from './paper.dto';
export * from './request.dto';

View File

@ -1,7 +1,5 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger";
import { IsArray, IsDefined, IsIn, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { IsArray, IsDefined, IsIn, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";
import { EsQueryDto } from "./es-query.dto";
import { SearchQueryDto } from "./search-q.dto";
/** /**
* List of allowed properties in this DTO * List of allowed properties in this DTO

View File

@ -1,5 +1,5 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger";
import { IsDefined, IsIn, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { IsDefined, IsNotEmpty, IsOptional } from "class-validator";
import { EsQueryDto } from "./es-query.dto"; import { EsQueryDto } from "./es-query.dto";
import { SearchQueryDto } from "./search-q.dto"; import { SearchQueryDto } from "./search-q.dto";

View File

@ -1,5 +1,5 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger";
import { IsDefined, IsIn, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { IsDefined, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator";
/** /**
* List of allowed properties in this DTO * List of allowed properties in this DTO

View File

@ -1,5 +1,5 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger";
import { IsArray, IsDefined, IsInt, IsNotEmpty, IsOptional, IsString } from "class-validator"; import { IsArray, IsDefined, IsInt, IsNotEmpty } from "class-validator";
import { EsResponseDto } from "./es-response.dto"; import { EsResponseDto } from "./es-response.dto";
/** /**

View File

@ -2,11 +2,38 @@
* Elasticsearch time-units * Elasticsearch time-units
*/ */
export enum EsTime { export enum EsTime {
/**
* Days
*/
days = 'd', days = 'd',
/**
* Hours
*/
hours = 'h', hours = 'h',
/**
* Minutes
*/
min = 'm', min = 'm',
/**
* Seconds
*/
sec = 's', sec = 's',
/**
* Milliseconds
*/
ms = 'ms', ms = 'ms',
/**
* Microseconds
*/
us = 'micros', us = 'micros',
/**
* Nanoseconds
*/
ns = 'nanos' ns = 'nanos'
} }

View File

@ -1,3 +1,4 @@
export * from './httpResponse' export * from './httpResponse'
export * from './roles.enum' export * from './roles.enum'
export * from './page-order.enum' export * from './page-order.enum'
export * from './es-time.enum'

View File

@ -2,6 +2,13 @@
* Page display order * Page display order
*/ */
export enum Order { export enum Order {
/**
* Ascending order
*/
ASC = 'asc', ASC = 'asc',
/**
* Descending order
*/
DESC = 'desc', DESC = 'desc',
} }

View File

@ -1 +1,3 @@
export * from './enums' export * from './enums'
export * from './dtos'
export * from './interfaces'

View File

@ -18,9 +18,4 @@
* Can't be specified with 'default_field' * Can't be specified with 'default_field'
*/ */
fields?: string[]; fields?: string[];
/**
*
*/
} }

View File

@ -1,4 +1,7 @@
export * from './http-response.interface'; export * from './http-response.interface'
export * from './page-meta.interface' export * from './page-meta.interface'
export * from './es-query.interface' export * from './es-query.interface'
export * from './es-query-string.interface' export * from './es-query-string.interface'
export * from './es-response-hits.interface'
export * from './es-pit.interface'
export * from './search-info.interface'

View File

@ -100,7 +100,9 @@ export class PageInterceptor implements NestInterceptor {
request.es_query.size += limit - 1; request.es_query.size += limit - 1;
reverse = true; reverse = true;
} else if (query.page == this.prevSearch.prevPage) { } else if (query.page == this.prevSearch.prevPage) {
//... // Caching should be HERE
request.es_query.sort = [{ _score: { order: 'asc' } }];
reverse = true;
} }
} else { } else {
this.prevSearch.pit = request.es_query.pit = await this.getPIT(1); this.prevSearch.pit = request.es_query.pit = await this.getPIT(1);

View File

@ -4,8 +4,6 @@ import { map, take } from "rxjs";
import { EsResponseDto } from "src/core/domain/dtos"; import { EsResponseDto } from "src/core/domain/dtos";
import { EsQueryDto } from "src/core/domain/dtos/es-query.dto"; import { EsQueryDto } from "src/core/domain/dtos/es-query.dto";
import { SearchResultDto } from "src/core/domain/dtos/search-result.dto"; import { SearchResultDto } from "src/core/domain/dtos/search-result.dto";
import { EsTime } from "src/core/domain/enums/es-time.enum";
import { EsPit } from "src/core/domain/interfaces/es-pit.interface";
/** /**
* Search service provider * Search service provider
@ -88,39 +86,3 @@ export class SearchService {
}); });
} }
} }
// let ESQ: EsQueryDto = new EsQueryDto;
// if (limit) ESQ.size = limit;
// ESQ.query = {
// query_string: {
// query: query_str,
// default_field: 'content',
// }
// }
// this.getPIT(1).then((pit) => {
// ESQ.pit = pit;
// });
/**
* Context
* // let es_query = { // DTO
// query: { // Interface
// query_string: { // Interface
// query: query_str,
// default_field: "content"
// }
// },
// }
*/
/**
* Single
* // let es_query = {
// query: {
// query_string: {
// query: 'id:' + uuid
// }
// },
// }
*/

View File

@ -1,5 +1,5 @@
import { plainToClass } from 'class-transformer'; import { plainToClass } from 'class-transformer';
import { validateSync, IsOptional } from 'class-validator'; import { validateSync } from 'class-validator';
/** /**
* env vatiables * env vatiables

View File

@ -1 +1,2 @@
export * from './app.module'; export * from './app.module';
export * from './search.module'

View File

@ -4,7 +4,7 @@ import { PapersController } from "src/application";
import { SearchService } from "../../core/services/common/search.service"; import { SearchService } from "../../core/services/common/search.service";
/** /**
* search module * Search module
*/ */
@Module({ @Module({
imports: [ imports: [

View File

@ -19,6 +19,9 @@ async function bootstrap() {
}) })
); );
/**
* Enabling URI-type versioning of the API
*/
app.enableVersioning({ app.enableVersioning({
type: VersioningType.URI, type: VersioningType.URI,
}); });