@golemio/energetics
Version:
Golemio Energetics Module
78 lines • 4.65 kB
JavaScript
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.BuildingsController = void 0;
const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken");
const AccessLimitationRepository_1 = require("../../repositories/AccessLimitationRepository");
const PrimaryBuildingsRepository_1 = require("../../repositories/PrimaryBuildingsRepository");
const BuildingTransformationFull_1 = require("../../transformations/BuildingTransformationFull");
const BuildingsTransformation_1 = require("../../transformations/BuildingsTransformation");
const Utils_1 = require("@golemio/core/dist/output-gateway/Utils");
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 BuildingsController = exports.BuildingsController = class BuildingsController extends AbstractController_1.AbstractController {
constructor(accessLimitationRepository, fullDataTransformation) {
super(accessLimitationRepository);
this.fullDataTransformation = fullDataTransformation;
this.getAll = async (req, res, next) => {
try {
const allowedOrganizations = await this.getAllowedOrganizationIds(req);
const fullParam = (0, Utils_1.parseBooleanQueryParam)(req.query.full);
const transformedResult = fullParam
? await this.getFullData(allowedOrganizations)
: await this.getPrimaryData(allowedOrganizations);
res.json(transformedResult);
}
catch (err) {
next(err);
}
};
this.getOne = async (req, res, next) => {
try {
const allowedOrganizations = await this.getAllowedOrganizationIds(req);
const id = parseInt(req.params.id);
const result = await this.buildingsRepository.GetOne(id, allowedOrganizations);
if (result === null) {
throw new golemio_errors_1.GeneralError("not_found", "V2BuildingsController", undefined, 404);
}
const transformedResult = this.fullDataTransformation.transformElement(result);
res.json(transformedResult);
}
catch (err) {
next(err);
}
};
this.getFullData = async (allowedOrganizations) => {
const result = await this.buildingsRepository.GetAllFull(allowedOrganizations);
const transformedResult = this.fullDataTransformation.transformArray(result);
return transformedResult;
};
this.getPrimaryData = async (allowedOrganizations) => {
const result = await this.buildingsRepository.GetAll(allowedOrganizations);
const transformedResult = this.transformation.transformArray(result);
return transformedResult;
};
this.buildingsRepository = new PrimaryBuildingsRepository_1.PrimaryBuildingsRepository();
this.transformation = new BuildingsTransformation_1.BuildingsTransformation();
}
};
exports.BuildingsController = BuildingsController = __decorate([
(0, tsyringe_1.injectable)(),
__param(0, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.AccessLimitationRepository)),
__param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.BuildingTransformationFull)),
__metadata("design:paramtypes", [AccessLimitationRepository_1.AccessLimitationRepository,
BuildingTransformationFull_1.BuildingTransformationFull])
], BuildingsController);
//# sourceMappingURL=BuildingsController.js.map
;