UNPKG

@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.

79 lines (78 loc) 2.67 kB
import { KeyDiffCache } from "../utils/cache/key-diff.cache.js"; //#region src/state/floor.store.ts var FloorStore = class FloorStore extends KeyDiffCache { logger; constructor(floorService, loggerFactory) { super(); this.floorService = floorService; this.logger = loggerFactory(FloorStore.name); } async loadStore() { const keyValues = (await this.floorService.list()).map((floor) => ({ key: floor.id, value: this.floorService.toDto(floor) })); await this.setKeyValuesBatch(keyValues, true); } async listCache() { const floors = await this.getAllValues(); if (floors?.length) return floors; await this.loadStore(); return await this.getAllValues(); } async create(input) { const floor = await this.floorService.create(input); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floor.id, floorDto, true); return floorDto; } async delete(floorId) { await this.floorService.delete(floorId); await this.deleteKeyValue(floorId); } async getFloor(floorId) { let floor = await this.getValue(floorId); if (floor) return floor; const dbFloor = await this.floorService.get(floorId); const floorDto = this.floorService.toDto(dbFloor); await this.setKeyValue(floorId, floorDto, true); return floorDto; } async update(floorId, input) { const floor = await this.floorService.update(floorId, input); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floorId, floorDto, true); return floorDto; } async updateName(floorId, name) { const floor = await this.floorService.updateName(floorId, name); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floorId, floorDto, true); return floorDto; } async updateFloorOrder(floorId, order) { const floor = await this.floorService.updateOrder(floorId, order); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floorId, floorDto, true); return floorDto; } async addOrUpdatePrinter(floorId, position) { const floor = await this.floorService.addOrUpdatePrinter(floorId, position); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floorId, floorDto, true); return floorDto; } async removePrinter(floorId, printerId) { const floor = await this.floorService.removePrinter(floorId, printerId); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floorId, floorDto, true); return floorDto; } async removePrinterFromAnyFloor(printerId) { await this.floorService.deletePrinterFromAnyFloor(printerId); await this.loadStore(); } }; //#endregion export { FloorStore }; //# sourceMappingURL=floor.store.js.map