UNPKG

@tomei/live-price

Version:

Tomei live-price Package

84 lines 4.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FeedConfig = void 0; const daemons_1 = require("../../components/daemons/daemons"); const feed_config_repository_1 = require("./feed-config.repository"); const activity_history_1 = require("@tomei/activity-history"); const log_1 = require("@tomei/log"); class FeedConfig { static loadConfig() { return __awaiter(this, void 0, void 0, function* () { const config = yield FeedConfig._Repo.getConfig(); if (config) { this.NotificationEmail = config.NotificationEmail || ''; this.CutOffReminderEveryXMinutes = config.CutOffReminderInternal || 0; this.ManualPriceReminderEveryXMinutes = config.ManualPriceReminderInternal || 0; } daemons_1.Daemons.ManualPriceReminder.restart(); daemons_1.Daemons.CutOffReminder.restart(); }); } static getNotificationEmail() { return FeedConfig.NotificationEmail; } static getCutOffReminderInternal() { return FeedConfig.CutOffReminderEveryXMinutes; } static getManualPriceReminderInternal() { return FeedConfig.ManualPriceReminderEveryXMinutes; } static updateConfig(config, loginUser, dbTransaction) { return __awaiter(this, void 0, void 0, function* () { try { const EntityValueBefore = yield FeedConfig._Repo.getConfig(dbTransaction); const payload = { NotificationEmail: config.NotificationEmail || this.NotificationEmail, CutOffReminderInternal: config.CutOffReminderInternal || this.CutOffReminderEveryXMinutes, ManualPriceReminderInternal: config.ManualPriceReminderInternal || this.ManualPriceReminderEveryXMinutes, UpdatedById: loginUser.ObjectId, UpdatedAt: new Date(), }; const result = yield FeedConfig._Repo.createConfig(payload, dbTransaction); this.NotificationEmail = payload.NotificationEmail; this.CutOffReminderEveryXMinutes = payload.CutOffReminderInternal; this.ManualPriceReminderEveryXMinutes = payload.ManualPriceReminderInternal; const activity = new activity_history_1.Activity(); activity.ActivityId = activity.createId(); activity.Description = 'Update Feed Config'; activity.Action = activity_history_1.ActionEnum.UPDATE; activity.EntityType = 'FeedConfig'; activity.EntityId = result.FeedConfigId; activity.EntityValueBefore = JSON.stringify(EntityValueBefore); activity.EntityValueAfter = JSON.stringify(result); yield activity.create(loginUser.ObjectId, dbTransaction); daemons_1.Daemons.ManualPriceReminder.restart(); daemons_1.Daemons.CutOffReminder.restart(); } catch (error) { yield log_1.ApplicationLog.error({ error, source: 'live-price', className: 'FeedConfig', methodName: 'updateConfig', transaction: dbTransaction, }); throw error; } }); } } exports.FeedConfig = FeedConfig; FeedConfig._Repo = new feed_config_repository_1.FeedConfigRepository(); //# sourceMappingURL=feed-config.js.map