@tomei/live-price
Version:
Tomei live-price Package
77 lines • 3.52 kB
JavaScript
;
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.FeedConfigRepository = void 0;
const general_1 = require("@tomei/general");
const price_feed_config_entity_1 = require("../../models/price-feed-config.entity");
const cuid2_1 = require("@paralleldrive/cuid2");
class FeedConfigRepository extends general_1.RepositoryBase {
constructor() {
super(price_feed_config_entity_1.default);
}
getConfig(dbTransaction) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield price_feed_config_entity_1.default.findOne({
order: [['UpdatedAt', 'DESC']],
transaction: dbTransaction,
});
}
catch (error) {
throw new Error(`An Error occured when retriving : ${error.message}`);
}
});
}
updateConfig(config, dbTransaction) {
return __awaiter(this, void 0, void 0, function* () {
try {
const oldConfig = yield this.getConfig(dbTransaction);
if (oldConfig) {
oldConfig.NotificationEmail = config.NotificationEmail;
oldConfig.CutOffReminderInternal = config.CutOffReminderInternal;
oldConfig.ManualPriceReminderInternal =
config.ManualPriceReminderInternal;
yield oldConfig.save({
transaction: dbTransaction,
});
}
}
catch (error) {
throw new Error(`An Error occured when updating : ${error.message}`);
}
});
}
createConfig(config, dbTransaction) {
return __awaiter(this, void 0, void 0, function* () {
try {
const newConfig = new price_feed_config_entity_1.default();
newConfig.NotificationEmail = config.NotificationEmail;
newConfig.CutOffReminderInternal = config.CutOffReminderInternal;
newConfig.ManualPriceReminderInternal =
config.ManualPriceReminderInternal;
newConfig.UpdatedById = config.UpdatedById;
newConfig.UpdatedAt = config.UpdatedAt;
const generateId = (0, cuid2_1.init)({
length: 10,
});
newConfig.FeedConfigId = generateId().toUpperCase();
return yield newConfig.save({
transaction: dbTransaction,
});
}
catch (error) {
throw new Error(`An Error occured when creating : ${error.message}`);
}
});
}
}
exports.FeedConfigRepository = FeedConfigRepository;
//# sourceMappingURL=feed-config.repository.js.map