benjamin658 / typeorm-cursor-pagination

Cursor-based pagination works with TypeORM Query Builder.
MIT License
186 stars 40 forks source link

feat(paginator) convert Order type to enum #49

Closed devx-opensource closed 2 years ago

devx-opensource commented 2 years ago

Avoid using string literals while allowing a developer to use the type at runtime as an enum


Hi!

I made a small change converting the Order type into an Enum. It allows a better use of the type in my opinion. With that feature, I'm able to do the following in my DTO:

import { IsInt,  } from 'class-validator';
import { Order } from 'typeorm-cursor-pagination';
import { ApiProperty } from '@nestjs/swagger';

export class PaginationDto<Entity> {
  // ...

  @IsIn(Object.values(Order))
  @ApiProperty({
    enum: Order,
  })
  order: Order = Order.DESC;

}

instead of

import { IsInt,  } from 'class-validator';
import { Order } from 'typeorm-cursor-pagination';
import { ApiProperty } from '@nestjs/swagger';

export class PaginationDto<Entity> {
  // ...

  @IsIn(['ASC', 'DESC'])
  @ApiProperty({
    enum: ['ASC', 'DESC'],
  })
  order: Order = 'DESC';

}
benjamin658 commented 2 years ago

Thanks again for your contribution!

Would you mind amending the commit message to feat(paginator): ..., so that the changelog generator can include this change.

Force push is ok to me.

devx-opensource commented 2 years ago

Thanks again for your contribution!

Would you mind amending the commit message to feat(paginator): ..., so that the changelog generator can include this change.

Force push is ok to me.

Done! I also reworked my test from the previous PR. It wasn't deterministic and would fail sometime.

Have a nice weekend.

benjamin658 commented 2 years ago

Thanks again, I will do the release tomorrow.

benjamin658 commented 2 years ago

The changes are included in the release v0.8.1.