UNPKG

@golemio/energetics

Version:
40 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccessLimitationRepository = void 0; const _sch_1 = require("../../schema-definitions"); const AccessLimitationModel_1 = require("../../schema-definitions/models/AccessLimitationModel"); const AbstractCachedRepository_1 = require("@golemio/core/dist/helpers/data-access/postgres/repositories/AbstractCachedRepository"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); class AccessLimitationRepository extends AbstractCachedRepository_1.AbstractCachedRepository { constructor(connector, log, cacheTTLInSeconds = 60 * 5) { super(connector, log, cacheTTLInSeconds); this.schema = _sch_1.EnergeticsSchema.pgSchema; this.tableName = AccessLimitationModel_1.AccessLimitationModel.TABLE_NAME; AccessLimitationModel_1.AccessLimitationModel.init(AccessLimitationModel_1.AccessLimitationModel.attributeModel, { tableName: AccessLimitationModel_1.AccessLimitationModel.TABLE_NAME, schema: _sch_1.EnergeticsSchema.pgSchema, sequelize: this.connector.getConnection(), }); } getAllInternal() { return AccessLimitationModel_1.AccessLimitationModel.findAll({ raw: true }); } async getOrganizationsByGroupName(groupName) { try { const data = await this.getAll(); const limitation = data.find((d) => d.group_name === groupName); if (!limitation) { throw new golemio_errors_1.GeneralError(`Access limitation for group ${groupName} not found`, this.constructor.name, undefined, 500); } return limitation.organization_ids; } catch (err) { if (err instanceof golemio_errors_1.GeneralError) { throw err; } throw new golemio_errors_1.GeneralError("Database error - getOrganizationsByGroupName", this.constructor.name, err, 500); } } } exports.AccessLimitationRepository = AccessLimitationRepository; //# sourceMappingURL=AccessLimitationRepository.js.map