UNPKG

@mbc-cqrs-serverless/core

Version:
63 lines 3.1 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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var HistoryService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.HistoryService = void 0; const common_1 = require("@nestjs/common"); const dynamodb_service_1 = require("../data-store/dynamodb.service"); const helpers_1 = require("../helpers"); const command_module_definition_1 = require("./command.module-definition"); const data_service_1 = require("./data.service"); const enums_1 = require("./enums"); const ttl_service_1 = require("./ttl.service"); const TABLE_NAME = Symbol('history'); let HistoryService = HistoryService_1 = class HistoryService { constructor(options, dynamoDbService, dataService, ttlService) { this.options = options; this.dynamoDbService = dynamoDbService; this.dataService = dataService; this.ttlService = ttlService; this.tableName = this.dynamoDbService.getTableName(this.options.tableName, enums_1.TableType.HISTORY); this.logger = new common_1.Logger(`${HistoryService_1.name}:${this.tableName}`); } set tableName(name) { this[TABLE_NAME] = name; } get tableName() { return this[TABLE_NAME]; } async publish(key) { const data = await this.dataService.getItem(key); if (!data) { return null; } data.sk = (0, helpers_1.addSortKeyVersion)(data.sk, data.version); const ttl = await this.ttlService.calculateTtl(enums_1.TableType.HISTORY, (0, helpers_1.getTenantCode)(key.pk)); data.ttl = ttl; this.logger.debug('publish::', data); return await this.dynamoDbService.putItem(this.tableName, data); } async getItem(key) { return await this.dynamoDbService.getItem(this.tableName, key); } }; exports.HistoryService = HistoryService; exports.HistoryService = HistoryService = HistoryService_1 = __decorate([ (0, common_1.Injectable)(), __param(0, (0, common_1.Inject)(command_module_definition_1.MODULE_OPTIONS_TOKEN)), __metadata("design:paramtypes", [Object, dynamodb_service_1.DynamoDbService, data_service_1.DataService, ttl_service_1.TtlService]) ], HistoryService); //# sourceMappingURL=history.service.js.map