rokot-notification
Version:
Rokot - [Rocketmakers](http://www.rocketmakers.com/) TypeScript NodeJs Platform
37 lines (36 loc) • 1.73 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const asyncFs_1 = require("./asyncFs");
class FileSystemContent {
constructor(basePath, logger) {
this.basePath = basePath;
this.logger = logger;
}
get(templateKey) {
return __awaiter(this, void 0, void 0, function* () {
const filePath = path.join(this.basePath, templateKey);
const exists = yield asyncFs_1.AsyncFs.existsAsync(filePath);
if (!exists) {
this.logger.warn(`An email template has been Generated: File not found '${filePath}' for notification template ${templateKey}`);
return `/* AUTOGEN: ${templateKey} */<p>${templateKey}</p>`;
}
try {
return yield asyncFs_1.AsyncFs.readFileAsync(filePath);
}
catch (err) {
this.logger.error(`Unable to read '${filePath}' for notification template ${templateKey}: ${err}`);
throw err;
}
});
}
}
exports.FileSystemContent = FileSystemContent;