UNPKG

db-models-nc

Version:
91 lines 4.95 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPlansFromSettings = exports.getDashboardSettings = void 0; const crypto_js_1 = require("crypto-js"); const database_1 = require("../database"); const config_1 = __importDefault(require("../config")); const { ENCRYPTION_SECRET_KEY } = config_1.default; const getDashboardSettings = () => __awaiter(void 0, void 0, void 0, function* () { var _a; const settings = (_a = (yield database_1.Settings.findOne({ where: { name: 'variables' } }))) === null || _a === void 0 ? void 0 : _a.value; const regularVariables = settings === null || settings === void 0 ? void 0 : settings.regularVariables; const encryptedVariables = settings === null || settings === void 0 ? void 0 : settings.encryptedVariables; // ? SPLIT_PERCENTAGE const nextUpToOwedSplitPercentage = regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.nextupToOwedSplitPercentage; if (!nextUpToOwedSplitPercentage) throw new Error('nextUpToOwedSplitPercentage not found'); // ? SYSTEM_ACTIVATION_DATE const systemActivationDate = regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.systemActivationDate; if (!systemActivationDate) throw new Error('systemActivatingDate not found'); // ? FETCH_MAX_COUNT const maxCount = Number(regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.fetchMaxCount); if (!maxCount) throw new Error('fetchMaxCount not found'); // ? EXPIRED_AFTER_IN_YEARS const expiredAfterInYears = Number(regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.expiredAfterInYears); if (!expiredAfterInYears) throw new Error('expiredAfterInYears not found'); // ? VIEWLIFT_EMAIL const email = regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.viewliftEmail; if (!email) throw new Error('viewLiftEmail not found'); // ? VIEWLIFT_ENDPOINT const viewliftEndpoint = regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.viewliftEndpoint; if (!viewliftEndpoint) throw new Error('viewliftEndpoint not found'); // ? VIEWLIFT_WATCHES_FETCH_LIMIT const limit = Number(regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.viewliftWatchesFetchLimit); if (!limit) throw new Error('viewLiftWatchesFetchLimit not found'); // ? VIEWLIFT_EMAIL const calculatorEndpoint = regularVariables === null || regularVariables === void 0 ? void 0 : regularVariables.calculatorEndpoint; if (!calculatorEndpoint) throw new Error('calculatorEndpoint not found'); let password = encryptedVariables === null || encryptedVariables === void 0 ? void 0 : encryptedVariables.viewliftPassword; if (!password) throw new Error('viewLiftPassword not found'); // ? VIEWLIFT_PASSWORD password = crypto_js_1.AES .decrypt(password, ENCRYPTION_SECRET_KEY) .toString(crypto_js_1.enc.Utf8); let stripeKey = encryptedVariables === null || encryptedVariables === void 0 ? void 0 : encryptedVariables.stripeKey; if (!stripeKey) throw new Error('stripeKey not found'); // ? stripeKey stripeKey = crypto_js_1.AES .decrypt(stripeKey, ENCRYPTION_SECRET_KEY) .toString(crypto_js_1.enc.Utf8); return { nextUpToOwedSplitPercentage, systemActivationDate, viewliftEndpoint, email, password, maxCount, expiredAfterInYears, limit, stripeKey, calculatorEndpoint, }; }); exports.getDashboardSettings = getDashboardSettings; const getPlansFromSettings = () => __awaiter(void 0, void 0, void 0, function* () { var _b; const plans = (_b = (yield database_1.Settings.findOne({ where: { name: 'plans' } }))) === null || _b === void 0 ? void 0 : _b.value; return plans; }); exports.getPlansFromSettings = getPlansFromSettings; //# sourceMappingURL=index.js.map