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.

160 lines (159 loc) 6.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "PrinterGroupController", { enumerable: true, get: function() { return PrinterGroupController; } }); const _printergroupserviceinterface = require("../services/interfaces/printer-group.service.interface"); const _serverconstants = require("../server.constants"); const _authenticate = require("../middleware/authenticate"); const _authorizationconstants = require("../constants/authorization.constants"); const _express = require("express"); const _awilixexpress = require("awilix-express"); const _paramconvertermiddleware = require("../middleware/param-converter.middleware"); function _ts_decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function _ts_metadata(k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); } class PrinterGroupController { printerGroupService; constructor(printerGroupService){ this.printerGroupService = printerGroupService; } async listGroups(req, res) { res.send(await this.printerGroupService.listGroups()); } async getGroup(req, res) { res.send(await this.printerGroupService.getGroupWithPrinters(req.local.id)); } async createGroup(req, res) { if (req.body.id) { delete req.body.id; } const entity = await this.printerGroupService.createGroup(req.body); res.send(entity); } async updateGroupName(req, res) { const entity = await this.printerGroupService.updateGroupName(req.local.id, req.body.name); res.send(entity); } async deleteGroup(req, res) { res.send(await this.printerGroupService.deleteGroup(req.local.id)); } async addPrinterToGroup(req, res) { const entity = await this.printerGroupService.addPrinterToGroup(req.local.id, req.body.printerId); res.send(this.printerGroupService.toDto(entity)); } async removePrinterFromGroup(req, res) { res.send(await this.printerGroupService.removePrinterFromGroup(req.local.id, req.body.printerId)); } } _ts_decorate([ (0, _awilixexpress.GET)(), (0, _awilixexpress.route)("/"), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "listGroups", null); _ts_decorate([ (0, _awilixexpress.GET)(), (0, _awilixexpress.route)("/:id"), (0, _awilixexpress.before)([ (0, _paramconvertermiddleware.ParamId)("id") ]), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "getGroup", null); _ts_decorate([ (0, _awilixexpress.POST)(), (0, _awilixexpress.route)("/"), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "createGroup", null); _ts_decorate([ (0, _awilixexpress.PATCH)(), (0, _awilixexpress.route)("/:id/name"), (0, _awilixexpress.before)([ (0, _paramconvertermiddleware.ParamId)("id") ]), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "updateGroupName", null); _ts_decorate([ (0, _awilixexpress.DELETE)(), (0, _awilixexpress.route)("/:id"), (0, _awilixexpress.before)([ (0, _paramconvertermiddleware.ParamId)("id") ]), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "deleteGroup", null); _ts_decorate([ (0, _awilixexpress.POST)(), (0, _awilixexpress.route)("/:id/printer"), (0, _awilixexpress.before)([ (0, _paramconvertermiddleware.ParamId)("id") ]), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "addPrinterToGroup", null); _ts_decorate([ (0, _awilixexpress.DELETE)(), (0, _awilixexpress.route)("/:id/printer"), (0, _awilixexpress.before)([ (0, _paramconvertermiddleware.ParamId)("id") ]), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _express.Request === "undefined" ? Object : _express.Request, typeof _express.Response === "undefined" ? Object : _express.Response ]), _ts_metadata("design:returntype", Promise) ], PrinterGroupController.prototype, "removePrinterFromGroup", null); PrinterGroupController = _ts_decorate([ (0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute + "/printer-group"), (0, _awilixexpress.before)([ (0, _authenticate.authenticate)(), (0, _authenticate.authorizeRoles)([ _authorizationconstants.ROLES.OPERATOR, _authorizationconstants.ROLES.ADMIN ]) ]), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _printergroupserviceinterface.IPrinterGroupService === "undefined" ? Object : _printergroupserviceinterface.IPrinterGroupService ]) ], PrinterGroupController); //# sourceMappingURL=printer-group.controller.js.map