@golemio/energetics
Version:
Golemio Energetics Module
77 lines • 4.87 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.V2OrganizationsController = void 0;
const parsePaginationParams_1 = require("../helpers/parsePaginationParams");
const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken");
const AccessLimitationRepository_1 = require("../../repositories/AccessLimitationRepository");
const OrganizationsRepository_1 = require("../../repositories/OrganizationsRepository");
const OrganizationDetailDtoTransformation_1 = require("../../transformations/OrganizationDetailDtoTransformation");
const OrganizationDtoTransformation_1 = require("../../transformations/OrganizationDtoTransformation");
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 V2OrganizationsController = exports.V2OrganizationsController = class V2OrganizationsController extends AbstractController_1.AbstractController {
constructor(organizationsRepository, transformation, transformationDetail, accessLimitationRepository) {
super(accessLimitationRepository);
this.organizationsRepository = organizationsRepository;
this.transformation = transformation;
this.transformationDetail = transformationDetail;
this.getAll = async (req, res, next) => {
try {
const allowedOrganizations = await this.getAllowedOrganizationIds(req);
const params = (0, parsePaginationParams_1.parsePaginationParams)(req);
const full = (0, Utils_1.parseBooleanQueryParam)(req.query.full) || false;
let result = [];
if (!full) {
result = this.transformation.transformArray(await this.organizationsRepository.GetAllPublic(params, allowedOrganizations));
}
else {
result = this.transformationDetail.transformArray(await this.organizationsRepository.GetAll(params, allowedOrganizations));
}
return res.json(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.organizationsRepository.GetOne(id, allowedOrganizations);
if (!result) {
return next(new golemio_errors_1.GeneralError("not_found", this.constructor.name, `Organization with id ${req.params.id} not found`, 404));
}
return res.json(this.transformationDetail.transformElement(result));
}
catch (err) {
return next(err);
}
};
}
};
exports.V2OrganizationsController = V2OrganizationsController = __decorate([
(0, tsyringe_1.injectable)(),
__param(0, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OrganizationsRepository)),
__param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OrganizationDtoTransformation)),
__param(2, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.OrganizationDetailDtoTransformation)),
__param(3, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.AccessLimitationRepository)),
__metadata("design:paramtypes", [OrganizationsRepository_1.OrganizationsRepository,
OrganizationDtoTransformation_1.OrganizationDtoTransformation,
OrganizationDetailDtoTransformation_1.OrganizationDetailDtoTransformation,
AccessLimitationRepository_1.AccessLimitationRepository])
], V2OrganizationsController);
//# sourceMappingURL=V2OrganizationsController.js.map
;