1.7.2 • Published 5 months ago
@buka/nestjs-type-helper v1.7.2
@nestjs/nestjs-type-helper
A set of helpers for project of NestJS + MikroORM + class-validator + class-transformer.
The purpose is to reduce duplicate decorators
For example, if we want create an Book entity. The code:
import { BigIntType, Entity, PrimaryKey, Property } from "@mikro-orm/core";
import { ApiProperty } from "@nestjs/swagger";
import { IsNumber, IsNumberString, Min } from "class-validator";
@Entity()
export class Book {
@ApiProperty({
type: "string",
description: "PK",
example: "1",
required: true,
})
@PrimaryKey({
type: new BigIntType("string"),
comment: "PK",
})
@IsNumberString()
id!: string;
@IsNumber()
@Min(0)
@ApiProperty({
type: "number",
description: "Book Price",
minimum: 0,
example: 10,
required: true,
})
@Property({
type: "int",
comment: "Book Price",
})
price!: number;
@ApiProperty({
type: "string",
description: "Book Created Time",
required: true,
})
@Property({
type: "datetime",
onCreate: () => new Date(),
defaultRaw: "CURRENT_TIMESTAMP",
comment: "Book Created Time",
})
createdAt: Date = new Date();
@ApiProperty({
type: "string",
description: "Book Last Updated Time",
required: true,
})
@Property({
type: "datetime",
onUpdate: () => new Date(),
defaultRaw: "CURRENT_TIMESTAMP",
comment: "Book Last Updated Time",
})
updatedAt: Date = new Date();
}Rewrite by @buka/nestjs-type-helpers:
import { BaseEntity, Entity } from "@mikro-orm/core";
import { EntityProperty } from "@buka/nestjs-type-helper";
@Entity()
export class Book extends BaseEntity {
@EntityProperty({
type: "int",
comment: "Book Price",
example: 10,
})
price!: number;
}Helpers
1.7.2
5 months ago
1.7.1
5 months ago
1.7.0
5 months ago
1.6.2
6 months ago
1.6.1
6 months ago
1.6.0
6 months ago
1.5.0
6 months ago
1.4.8
7 months ago
1.4.7
7 months ago
1.4.6
7 months ago
1.4.5
7 months ago
1.4.4
7 months ago
1.4.3
7 months ago
1.4.2
7 months ago
1.4.1
8 months ago
1.4.0
8 months ago
1.3.4
8 months ago
1.3.3
8 months ago
1.3.2
8 months ago
1.3.1
8 months ago
1.3.0
8 months ago
1.2.0
8 months ago
1.1.0
8 months ago
1.0.2
8 months ago
1.0.1
9 months ago