UNPKG

@riskmgmt/forerunnerdb

Version:

Forerunnerdb Angular 5 injectable service

45 lines (44 loc) 1.7 kB
import { Injectable } from "@angular/core"; import { DocumentDbService } from "./documentdb.service"; var DocumentService = /** @class */ (function () { function DocumentService(documentDataService, logger) { this.documentDataService = documentDataService; this.logger = logger; this.dataCached = {}; this.logger.info("DocumentService created"); } DocumentService.prototype.setDocument = function (userId, data) { var _this = this; this.logger.info("setDocument called"); return this.documentDataService.update(this.collectionName, { _id: this.docId + ":" + userId, item: data }) .then(function () { _this.dataCached[userId] = data.item; return _this.dataCached[userId]; }); }; DocumentService.prototype.getDocument = function (userId) { var _this = this; this.logger.info("getDocument called"); if (!this.dataCached[userId]) { return this.documentDataService.get(this.collectionName, this.docId + ":" + userId) .then(function (data) { if (data == null) { return null; } _this.dataCached[userId] = data.item; return _this.dataCached[userId]; }); } return new Promise(function (fulfill) { return fulfill(_this.dataCached[userId]); }); }; DocumentService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ DocumentService.ctorParameters = function () { return [ { type: DocumentDbService, }, null, ]; }; return DocumentService; }()); export { DocumentService };