@fdm-monster/server
Version:
FDM Monster is a bulk OctoPrint, Klipper, PrusaLink and BambuLab manager to set up, configure and monitor 3D printers. Our aim is to provide neat overview over your farm.
86 lines (85 loc) • 3.86 kB
JavaScript
import { BaseService } from "./base.service.js";
import { validateInput } from "../../handlers/validators.js";
import { credentialSettingsKey, frontendSettingKey, getDefaultSettings, serverSettingsKey, timeoutSettingKey, wizardSettingKey } from "../../constants/server-settings.constants.js";
import { credentialCoreSettingUpdateSchema, frontendSettingsUpdateSchema, jwtSecretCredentialSettingUpdateSchema, serverSettingsUpdateSchema, slicerApiKeyUpdateSchema, timeoutSettingsUpdateSchema, wizardUpdateSchema } from "../validators/settings-service.validation.js";
import { Settings } from "../../entities/settings.entity.js";
import "../../entities/index.js";
import { SettingsDto } from "../interfaces/settings.dto.js";
import { migrateSettingsRuntime } from "../../shared/runtime-settings.migration.js";
//#region src/services/orm/settings.service.ts
var SettingsService = class extends BaseService(Settings, SettingsDto) {
toDto(entity) {
return {
[serverSettingsKey]: entity[serverSettingsKey],
[frontendSettingKey]: entity[frontendSettingKey],
[wizardSettingKey]: entity[wizardSettingKey],
[timeoutSettingKey]: entity[timeoutSettingKey]
};
}
async getOrCreate() {
let settings = await this.getOptional();
if (settings) {
settings = migrateSettingsRuntime(settings);
const settingsId = settings.id;
return await this.update(settingsId, settings);
} else return await this.create(getDefaultSettings());
}
async updateServerSettings(update) {
const validatedInput = await validateInput(update, serverSettingsUpdateSchema);
const entity = await this.getOrCreate();
entity[serverSettingsKey] = validatedInput;
await this.update(entity.id, entity);
return entity;
}
async updateJwtSecretCredentialSetting(update) {
const validatedInput = await validateInput(update, jwtSecretCredentialSettingUpdateSchema);
const entity = await this.getOrCreate();
entity[credentialSettingsKey].jwtSecret = validatedInput.jwtSecret;
await this.update(entity.id, entity);
return entity;
}
async updateCoreCredentialSettings(update) {
const validatedInput = await validateInput(update, credentialCoreSettingUpdateSchema);
const entity = await this.getOrCreate();
entity[credentialSettingsKey].refreshTokenExpiry = validatedInput.refreshTokenExpiry;
entity[credentialSettingsKey].refreshTokenAttempts = validatedInput.refreshTokenAttempts;
entity[credentialSettingsKey].jwtExpiresIn = validatedInput.jwtExpiresIn;
await this.update(entity.id, entity);
return entity;
}
async updateSlicerApiKey(update) {
const validatedInput = await validateInput(update, slicerApiKeyUpdateSchema);
const entity = await this.getOrCreate();
entity[credentialSettingsKey].slicerApiKey = validatedInput.slicerApiKey;
await this.update(entity.id, entity);
return entity;
}
async updateFrontendSettings(update) {
const validatedInput = await validateInput(update, frontendSettingsUpdateSchema);
const entity = await this.getOrCreate();
entity[frontendSettingKey] = validatedInput;
await this.update(entity.id, entity);
return entity;
}
async updateTimeoutSettings(update) {
const validatedInput = await validateInput(update, timeoutSettingsUpdateSchema);
const entity = await this.getOrCreate();
entity[timeoutSettingKey] = validatedInput;
await this.update(entity.id, entity);
return entity;
}
async updateWizardSettings(update) {
const validatedInput = await validateInput(update, wizardUpdateSchema);
const entity = await this.getOrCreate();
entity[wizardSettingKey] = validatedInput;
await this.update(entity.id, entity);
return entity;
}
async getOptional() {
const settingsList = await this.repository.find({ take: 1 });
return settingsList?.length ? settingsList[0] : null;
}
};
//#endregion
export { SettingsService };
//# sourceMappingURL=settings.service.js.map