UNPKG

@fdm-monster/server

Version:

FDM Monster is a bulk OctoPrint manager to set up, configure and monitor 3D printers. Our aim is to provide extremely optimized websocket performance and reliability.

98 lines (97 loc) 3.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "FloorStore", { enumerable: true, get: function() { return FloorStore; } }); const _keydiffcache = require("../utils/cache/key-diff.cache"); class FloorStore extends _keydiffcache.KeyDiffCache { floorService; logger; constructor(floorService, loggerFactory){ super(), this.floorService = floorService; this.logger = loggerFactory(FloorStore.name); } async loadStore() { const floors = await this.floorService.list(); if (!floors?.length) { this.logger.log("Creating default floor as non existed"); const floor = await this.floorService.createDefaultFloor(); const floorDto = this.floorService.toDto(floor); await this.setKeyValue(floor.id, floorDto, true); return; } const keyValues = floors.map((floor)=>({ key: floor.id.toString(), 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 updateFloorNumber(floorId, floorLevel) { const floor = await this.floorService.updateLevel(floorId, floorLevel); 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(); } } //# sourceMappingURL=floor.store.js.map