@nest-omni/core 3.1.1-19 → 3.1.1-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { AbstractDto, AbstractTranslationDto } from './dto/abstract.dto';
|
|
2
2
|
import { LanguageCode } from '../constants';
|
|
3
|
+
import type { Constructor } from './types';
|
|
3
4
|
export declare abstract class AbstractDtoEntity<DTO, O = never> {
|
|
4
5
|
translations?: AbstractTranslationEntity[];
|
|
5
6
|
toDto(options?: O): DTO;
|
|
6
7
|
}
|
|
8
|
+
export declare function WithDto<Entity, DTO, O = never>(): {
|
|
9
|
+
new (): {
|
|
10
|
+
dtoClass?: Constructor<DTO, [Entity, O]>;
|
|
11
|
+
toDto(this: Entity, options?: O): DTO;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
7
14
|
export declare abstract class AbstractBaseEntity<DTO, O> extends AbstractDtoEntity<DTO, O> {
|
|
8
15
|
createdAt: Date;
|
|
9
16
|
updatedAt: Date;
|
|
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.AbstractUuidPrimaryEntity = exports.AbstractTranslationEntity = exports.AbstractEntity = exports.AbstractBaseEntity = exports.AbstractDtoEntity = void 0;
|
|
13
|
+
exports.WithDto = WithDto;
|
|
13
14
|
const typeorm_1 = require("typeorm");
|
|
14
15
|
const decorators_1 = require("../decorators");
|
|
15
16
|
const constants_1 = require("../constants");
|
|
@@ -24,6 +25,17 @@ class AbstractDtoEntity {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
exports.AbstractDtoEntity = AbstractDtoEntity;
|
|
28
|
+
function WithDto() {
|
|
29
|
+
return class Base {
|
|
30
|
+
toDto(options) {
|
|
31
|
+
const dtoClass = this.dtoClass || Object.getPrototypeOf(this).dtoClass;
|
|
32
|
+
if (!dtoClass) {
|
|
33
|
+
throw new Error(`You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`);
|
|
34
|
+
}
|
|
35
|
+
return new dtoClass(this, options);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
27
39
|
class AbstractBaseEntity extends AbstractDtoEntity {
|
|
28
40
|
}
|
|
29
41
|
exports.AbstractBaseEntity = AbstractBaseEntity;
|
|
@@ -2,3 +2,4 @@ import type { AbstractEntity } from '../common/abstract.entity';
|
|
|
2
2
|
import type { AbstractDto } from '../common/dto/abstract.dto';
|
|
3
3
|
import type { Constructor } from '../common/types';
|
|
4
4
|
export declare function UseDto(dtoClass: Constructor<AbstractDto, [AbstractEntity, unknown]>): ClassDecorator;
|
|
5
|
+
export declare function UseDto<Entity, Dto extends AbstractDto>(dtoClass: Constructor<Dto, [Entity, unknown?]>): ClassDecorator;
|
|
@@ -4,5 +4,15 @@ exports.UseDto = UseDto;
|
|
|
4
4
|
function UseDto(dtoClass) {
|
|
5
5
|
return (ctor) => {
|
|
6
6
|
ctor.prototype.dtoClass = dtoClass;
|
|
7
|
+
ctor.dtoClass = dtoClass;
|
|
8
|
+
if (!ctor.prototype.toDto) {
|
|
9
|
+
ctor.prototype.toDto = function (options) {
|
|
10
|
+
const DtoClass = this.constructor.dtoClass || dtoClass;
|
|
11
|
+
if (!DtoClass) {
|
|
12
|
+
throw new Error(`You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`);
|
|
13
|
+
}
|
|
14
|
+
return new DtoClass(this, options);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
7
17
|
};
|
|
8
18
|
}
|
package/package.json
CHANGED