UNPKG

@grouparoo/core

Version:
72 lines (71 loc) 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SettingEdit = exports.SettingCoreClusterName = exports.SettingsList = void 0; const authenticatedAction_1 = require("../classes/actions/authenticatedAction"); const optionallyAuthenticatedAction_1 = require("../classes/actions/optionallyAuthenticatedAction"); const plugin_1 = require("../modules/plugin"); const Setting_1 = require("../models/Setting"); const apiData_1 = require("../modules/apiData"); class SettingsList extends authenticatedAction_1.AuthenticatedAction { constructor() { super(...arguments); this.name = "settings:list"; this.description = "list all the settings"; this.outputExample = {}; this.permission = { topic: "system", mode: "read" }; this.inputs = { order: { required: false, formatter: apiData_1.APIData.ensureArray, default: [ ["pluginName", "desc"], ["title", "desc"], ["key", "desc"], ], }, }; } async runWithinTransaction({ params }) { const setting = await Setting_1.Setting.findAll({ order: params.order }); return { settings: await Promise.all(setting.map((s) => s.apiData())), }; } } exports.SettingsList = SettingsList; // only this setting can be shown without being authenticated class SettingCoreClusterName extends optionallyAuthenticatedAction_1.OptionallyAuthenticatedAction { constructor() { super(...arguments); this.name = "setting:view:core:cluster-name"; this.description = "get the value for the cluster name setting"; this.outputExample = {}; this.permission = { topic: "system", mode: "read" }; } async runWithinTransaction() { const clusterNameSetting = await Setting_1.Setting.findOne({ where: { pluginName: "core", key: "cluster-name" }, }); return { setting: await clusterNameSetting.apiData() }; } } exports.SettingCoreClusterName = SettingCoreClusterName; class SettingEdit extends authenticatedAction_1.AuthenticatedAction { constructor() { super(...arguments); this.name = "setting:edit"; this.description = "edit a setting"; this.outputExample = {}; this.permission = { topic: "system", mode: "write" }; this.inputs = { id: { required: true }, value: { required: true }, }; } async runWithinTransaction({ params }) { let setting = await Setting_1.Setting.findById(params.id); setting = await plugin_1.plugin.updateSetting(setting.pluginName, setting.key, params.value); return { setting: await setting.apiData() }; } } exports.SettingEdit = SettingEdit;