Skip to content

Commit 2dd02a0

Browse files
committed
fix: not found sort fields
1 parent aa4c9ab commit 2dd02a0

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/app.module.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
2-
import { AppController } from './app.controller';
3-
import { AppService } from './app.service';
42
import { MovieModule } from './movie/movie.module';
53
import { MongooseModule } from '@nestjs/mongoose';
64
import { ConfigModule, ConfigService } from '@nestjs/config';
@@ -16,7 +14,6 @@ import { ReviewController } from './review/review.controller';
1614
import { PersonController } from './person/person.controller';
1715
import { ImageController } from './image/image.controller';
1816
import { LoggerModule } from 'nestjs-pino';
19-
import pino from 'pino';
2017
@Module({
2118
imports: [
2219
LoggerModule.forRoot(

src/common/base/base.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export abstract class BaseService<T> implements IBaseService<T> {
2626
.limit(query.limit)
2727
.skip(query.skip)
2828
.select(query.select)
29-
.sort(query.sort?.length ? query.sort : { 'votes.kp': -1 })
29+
.sort(Object.keys(query.sort)?.length ? query.sort : { 'votes.kp': -1 })
3030
.exec(),
3131
]);
3232

src/common/dto/query/tools.query.dto.ts

+18
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,22 @@ export class ToolsQueryDto {
1111
@Expose()
1212
@IsArray()
1313
selectFields: string[];
14+
15+
@ApiPropertyOptional({
16+
description: 'Поля по которым нужно отсортировать. Доступны все любые поля из модели!',
17+
example: 'year | rating.kp | votes.kp',
18+
isArray: true,
19+
})
20+
@Expose()
21+
@IsArray()
22+
sortField: string;
23+
24+
@ApiPropertyOptional({
25+
description: 'Тип сортировки. Для каждого поля нужно указать тип сортировки: 1 - по возрастанию -1 - по убыванию',
26+
example: '1 | -1',
27+
isArray: true,
28+
})
29+
@Expose()
30+
@IsArray()
31+
sortType: string[];
1432
}

0 commit comments

Comments
 (0)