[英]How to work with more than one sequelize DB connection in NestJS
[英]How to extend more than one dto class in Nestjs
我是nest.js
的新手,对此有疑问。
我想将多个Dto
扩展到我的主要dto
class,但我知道不可能扩展超过 2 个dto
类。 你知道怎么做吗?
这是我的主要dto
class:
export class CarDto extends PickupLocationDto {
@ApiProperty({ example: 'Aventador', description: 'The car name' })
readonly modelName: string;
}
最近我只能将它从PickupLocationDto
扩展到 class,但我想再将一个dto
class 扩展到这个CarDto
class。
任何帮助表示赞赏。
由于我使用 swagger,因此使用@nestjs/mapped-types
package 不会显示来自相交 dto 的所有变量。 因此,我使用 swagger 中的 IntersectionType
import { ApiProperty, IntersectionType } from '@nestjs/swagger';
export class Dto3 extends IntersectionType(
Dto1,
Dto2,
) {}
您可以使用mapped-types
来做到这一点,首先您需要安装 package ( yarn add @nestjs/mapped-types
) 然后像这样使用IntersectionType
:
import { IntersectionType } from '@nestjs/mapped-types';
export class Dto3 extends IntersectionType(
Dto1,
Dto2,
) {}
您还可以使用 extend 关键字来扩展 DTO class
export class Dto3 extends Dto1 {
public readonly dtoField: Dto2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.