"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "FloorController", {
    enumerable: true,
    get: function() {
        return FloorController;
    }
});
const _express = require("express");
const _floorstore = require("../state/floor.store");
const _authorizationconstants = require("../constants/authorization.constants");
const _serverconstants = require("../server.constants");
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
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 FloorController {
    floorStore;
    constructor(floorStore){
        this.floorStore = floorStore;
    }
    async list(req, res) {
        const floors = await this.floorStore.listCache();
        res.send(floors);
    }
    async get(req, res) {
        const floor = await this.floorStore.getFloor(req.local.id);
        res.send(floor);
    }
    async delete(req, res) {
        await this.floorStore.delete(req.local.id);
        res.send();
    }
    async create(req, res) {
        const floor = await this.floorStore.create(req.body);
        res.send(floor);
    }
    async updateName(req, res) {
        const floor = await this.floorStore.updateName(req.local.id, req.body.name);
        res.send(floor);
    }
    async updateFloorOrder(req, res) {
        const floor = await this.floorStore.updateFloorOrder(req.local.id, req.body.order);
        res.send(floor);
    }
    async addPrinterToFloor(req, res) {
        const floor = await this.floorStore.addOrUpdatePrinter(req.local.id, req.body);
        res.send(floor);
    }
    async removePrinterFromFloor(req, res) {
        const floor = await this.floorStore.removePrinter(req.local.id, req.body.printerId);
        res.send(floor);
    }
}
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.List)
    ]),
    _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)
], FloorController.prototype, "list", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/:id"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Get),
        (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)
], FloorController.prototype, "get", null);
_ts_decorate([
    (0, _awilixexpress.DELETE)(),
    (0, _awilixexpress.route)("/:id"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Delete),
        (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)
], FloorController.prototype, "delete", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Create)
    ]),
    _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)
], FloorController.prototype, "create", null);
_ts_decorate([
    (0, _awilixexpress.PATCH)(),
    (0, _awilixexpress.route)("/:id/name"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Update),
        (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)
], FloorController.prototype, "updateName", null);
_ts_decorate([
    (0, _awilixexpress.PATCH)(),
    (0, _awilixexpress.route)("/:id/floor-order"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Update),
        (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)
], FloorController.prototype, "updateFloorOrder", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/:id/printer"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Update),
        (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)
], FloorController.prototype, "addPrinterToFloor", null);
_ts_decorate([
    (0, _awilixexpress.DELETE)(),
    (0, _awilixexpress.route)("/:id/printer"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.Floors.Update),
        (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)
], FloorController.prototype, "removePrinterFromFloor", null);
FloorController = _ts_decorate([
    (0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute + "/floor"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)()
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _floorstore.FloorStore === "undefined" ? Object : _floorstore.FloorStore
    ])
], FloorController);

//# sourceMappingURL=floor.controller.js.map