UNPKG

@golemio/energetics

Version:
65 lines 3.89 kB
"use strict"; var __decorate = (this && this.__decorate) || function (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; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.V2DevicesController = void 0; const parsePaginationParams_1 = require("../helpers/parsePaginationParams"); const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken"); const AccessLimitationRepository_1 = require("../../repositories/AccessLimitationRepository"); const DevicesRepository_1 = require("../../repositories/DevicesRepository"); const DeviceDtoTransformation_1 = require("../../transformations/DeviceDtoTransformation"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe"); const AbstractController_1 = require("./AbstractController"); let V2DevicesController = exports.V2DevicesController = class V2DevicesController extends AbstractController_1.AbstractController { constructor(devicesRepository, transformation, accessLimitationRepository) { super(accessLimitationRepository); this.devicesRepository = devicesRepository; this.transformation = transformation; this.getAll = async (req, res, next) => { try { const allowedOrganizations = await this.getAllowedOrganizationIds(req); const params = (0, parsePaginationParams_1.parsePaginationParams)(req); const result = await this.devicesRepository.GetAll(params, allowedOrganizations); return res.json(this.transformation.transformArray(result)); } catch (err) { return next(err); } }; this.getOne = async (req, res, next) => { try { const allowedOrganizations = await this.getAllowedOrganizationIds(req); const id = req.params.id; const result = await this.devicesRepository.GetOne(id, allowedOrganizations); if (!result) { return next(new golemio_errors_1.GeneralError("not_found", this.constructor.name, `Device with id ${req.params.id} not found`, 404)); } return res.json(this.transformation.transformElement(result)); } catch (err) { return next(err); } }; } }; exports.V2DevicesController = V2DevicesController = __decorate([ (0, tsyringe_1.injectable)(), __param(0, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.DevicesRepository)), __param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.DeviceDtoTransformation)), __param(2, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.AccessLimitationRepository)), __metadata("design:paramtypes", [DevicesRepository_1.DevicesRepository, DeviceDtoTransformation_1.DeviceDtoTransformation, AccessLimitationRepository_1.AccessLimitationRepository]) ], V2DevicesController); //# sourceMappingURL=V2DevicesController.js.map