"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    CustomGcodeController: function() {
        return CustomGcodeController;
    },
    default: function() {
        return _default;
    }
});
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
const _serverconstants = require("../server.constants");
const _authorizationconstants = require("../constants/authorization.constants");
const _validators = require("../handlers/validators");
const _genericvalidation = require("./validation/generic.validation");
const _printer = require("../middleware/printer");
class CustomGcodeController {
    customGCodeService;
    isTypeormMode;
    constructor({ customGCodeService, isTypeormMode }){
        this.customGCodeService = customGCodeService;
        this.isTypeormMode = isTypeormMode;
    }
    async list(req, res) {
        const entities = await this.customGCodeService.list();
        res.send(entities.map((e)=>this.customGCodeService.toDto(e)));
    }
    async get(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const entity = await this.customGCodeService.get(id);
        res.send(this.customGCodeService.toDto(entity));
    }
    async sendEmergencyM112(req, res) {
        const { printerApi } = (0, _validators.getScopedPrinter)(req);
        await printerApi.quickStop();
        res.send();
    }
    async create(req, res) {
        const entity = await this.customGCodeService.create(req.body);
        res.send(this.customGCodeService.toDto(entity));
    }
    async delete(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        await this.customGCodeService.delete(id);
        res.send();
    }
    async update(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const updatedScript = await this.customGCodeService.update(id, req.body);
        res.send(this.customGCodeService.toDto(updatedScript));
    }
}
const _default = (0, _awilixexpress.createController)(CustomGcodeController).prefix(`${_serverconstants.AppConstants.apiRoute}/custom-gcode`).before([
    (0, _authenticate.authenticate)(),
    (0, _authenticate.authorizeRoles)([
        _authorizationconstants.ROLES.ADMIN,
        _authorizationconstants.ROLES.OPERATOR
    ])
]).get("/", "list").get("/:id", "get").post("/", "create").post("/send-emergency-m112/:printerId", "sendEmergencyM112", {
    before: [
        (0, _printer.printerResolveMiddleware)("printerId")
    ]
}).delete("/:id", "delete").put("/:id", "update");

//# sourceMappingURL=custom-gcode.controller.js.map