UNPKG

@nest-kr/integration

Version:

```cli npm i @nest-kr/integration ```

48 lines (47 loc) 2.41 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@nestjs/common"); const IntegrationEventEntity_1 = require("./IntegrationEventEntity"); const IntegrationEventFactory_1 = require("../../domain/IntegrationEventFactory"); let IntegrationEventMapper = class IntegrationEventMapper { constructor(integrationEventFactory) { this.integrationEventFactory = integrationEventFactory; } toDomain(entity) { const { id } = entity; const { topicArn } = entity; const { subject } = entity; const headers = JSON.parse(entity.headers); const data = JSON.parse(entity.data); const { publishedAt } = entity; const { createdAt } = entity; const { signature } = entity; return this.integrationEventFactory.reconstitute(id, topicArn, subject, headers, data, publishedAt, createdAt, signature); } toEntity(domain) { const entity = new IntegrationEventEntity_1.IntegrationEventEntity(); entity.id = domain.id; entity.topicArn = domain.topicArn; entity.subject = domain.subject; entity.headers = JSON.stringify(domain.headers); entity.data = JSON.stringify(domain.data); entity.publishedAt = domain.publishedAt; entity.createdAt = domain.createdAt; entity.signature = domain.signature; return entity; } }; IntegrationEventMapper = __decorate([ common_1.Injectable(), __metadata("design:paramtypes", [IntegrationEventFactory_1.IntegrationEventFactory]) ], IntegrationEventMapper); exports.IntegrationEventMapper = IntegrationEventMapper;