nestjs-response-dto-mapper
Version:
👀 Response to DTO mapper for NestJS and Swagger with class-transformer
25 lines (24 loc) • 853 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrapToClassInterceptor = void 0;
const common_1 = require("@nestjs/common");
const rxjs_1 = require("rxjs");
const WrapToClassInterceptor = (type) => {
class MixinInterceptor {
intercept(context, next) {
return next
.handle()
.pipe((0, rxjs_1.map)((value) => value && typeof value === 'object'
? Array.isArray(value)
? value.map((element) => this.wrap(element))
: this.wrap(value)
: value));
}
wrap(value) {
return Object.assign(new type(), value);
}
}
const Interceptor = (0, common_1.mixin)(MixinInterceptor);
return Interceptor;
};
exports.WrapToClassInterceptor = WrapToClassInterceptor;