@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.
150 lines (149 loc) • 6.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "CustomGcodeController", {
enumerable: true,
get: function() {
return CustomGcodeController;
}
});
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
const _serverconstants = require("../server.constants");
const _authorizationconstants = require("../constants/authorization.constants");
const _printer = require("../middleware/printer");
const _express = require("express");
const _customgcodeserviceinterface = require("../services/interfaces/custom-gcode.service.interface");
const _printerresolver = require("../middleware/printer-resolver");
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 CustomGcodeController {
customGCodeService;
isTypeormMode;
constructor(customGCodeService, isTypeormMode){
this.customGCodeService = customGCodeService;
this.isTypeormMode = isTypeormMode;
}
async sendEmergencyM112(req, res) {
const { printerApi } = (0, _printerresolver.getScopedPrinter)(req);
await printerApi.quickStop();
res.send();
}
async list(req, res) {
const entities = await this.customGCodeService.list();
res.send(entities.map((e)=>this.customGCodeService.toDto(e)));
}
async create(req, res) {
const entity = await this.customGCodeService.create(req.body);
res.send(this.customGCodeService.toDto(entity));
}
async get(req, res) {
const entity = await this.customGCodeService.get(req.local.id);
res.send(this.customGCodeService.toDto(entity));
}
async update(req, res) {
const updatedScript = await this.customGCodeService.update(req.local.id, req.body);
res.send(this.customGCodeService.toDto(updatedScript));
}
async delete(req, res) {
await this.customGCodeService.delete(req.local.id);
res.send();
}
}
_ts_decorate([
(0, _awilixexpress.POST)(),
(0, _awilixexpress.route)("/send-emergency-m112/:printerId"),
(0, _awilixexpress.before)([
(0, _printer.printerResolveMiddleware)("printerId")
]),
_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)
], CustomGcodeController.prototype, "sendEmergencyM112", null);
_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)
], CustomGcodeController.prototype, "list", 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)
], CustomGcodeController.prototype, "create", 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)
], CustomGcodeController.prototype, "get", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(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)
], CustomGcodeController.prototype, "update", 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)
], CustomGcodeController.prototype, "delete", null);
CustomGcodeController = _ts_decorate([
(0, _awilixexpress.route)(`${_serverconstants.AppConstants.apiRoute}/custom-gcode`),
(0, _awilixexpress.before)([
(0, _authenticate.authenticate)(),
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN,
_authorizationconstants.ROLES.OPERATOR
])
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _customgcodeserviceinterface.ICustomGcodeService === "undefined" ? Object : _customgcodeserviceinterface.ICustomGcodeService,
Boolean
])
], CustomGcodeController);
//# sourceMappingURL=custom-gcode.controller.js.map