UNPKG

@sourceloop/ctrl-plane-tenant-management-service

Version:

Tenant Management microservice for SaaS control plane

300 lines 11.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TenantController = void 0; const tslib_1 = require("tslib"); const repository_1 = require("@loopback/repository"); const rest_1 = require("@loopback/rest"); const core_1 = require("@sourceloop/core"); const loopback4_authentication_1 = require("loopback4-authentication"); const loopback4_authorization_1 = require("loopback4-authorization"); const tenant_repository_1 = require("../repositories/tenant.repository"); const models_1 = require("../models"); const permissions_1 = require("../permissions"); const core_2 = require("@loopback/core"); const services_1 = require("../services"); const basePath = '/tenants'; let TenantController = class TenantController { constructor(tenantRepository, onboarding, provisioningService) { this.tenantRepository = tenantRepository; this.onboarding = onboarding; this.provisioningService = provisioningService; } async create(dto) { return this.onboarding.onboard(dto); } async provision(subscription, id) { const tenantDetails = await this.tenantRepository.findById(id, { include: ['contacts', 'address'], }); return this.provisioningService.provisionTenant(tenantDetails, subscription); } async count(where) { return this.tenantRepository.count(where); } async find(filter) { return this.tenantRepository.find(filter); } async updateAll(tenant, where) { return this.tenantRepository.updateAll(tenant, where); } async findById(id, filter) { return this.tenantRepository.findById(id, filter); } async updateById(id, tenant) { await this.tenantRepository.updateById(id, tenant); } async replaceById(id, tenant) { await this.tenantRepository.replaceById(id, tenant); } async deleteById(id) { await this.tenantRepository.deleteById(id); } }; exports.TenantController = TenantController; tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.CreateTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.post)(basePath, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Tenant model instance', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant) }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.TenantOnboardDTO, { title: 'NewTenantOnboarding', exclude: [], }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [models_1.TenantOnboardDTO]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "create", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ProvisionTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.post)(`${basePath}/{id}/provision`, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Provisioning success', }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.SubscriptionDTO, { title: 'SubscriptionDTO', }), }, }, })), tslib_1.__param(1, rest_1.param.path.string('id')), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [models_1.SubscriptionDTO, String]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "provision", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.get)(`${basePath}/count`, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Tenant model count', content: { [core_1.CONTENT_TYPE.JSON]: { schema: repository_1.CountSchema } }, }, }, }), tslib_1.__param(0, rest_1.param.where(models_1.Tenant)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "count", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.get)(basePath, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Array of Tenant model instances', content: { [core_1.CONTENT_TYPE.JSON]: { schema: { type: 'array', items: (0, rest_1.getModelSchemaRef)(models_1.Tenant, { includeRelations: true }), }, }, }, }, }, }), tslib_1.__param(0, rest_1.param.filter(models_1.Tenant)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "find", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.patch)(basePath, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Tenant PATCH success', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant), }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant, { partial: true }), }, }, })), tslib_1.__param(1, rest_1.param.where(models_1.Tenant)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [models_1.Tenant, Object]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "updateAll", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.get)(`${basePath}/{id}`, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Tenant model instance', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant) }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, rest_1.param.filter(models_1.Tenant, { exclude: 'where' })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, Object]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "findById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.patch)(`${basePath}/{id}`, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Tenant PATCH success', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant), }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, (0, rest_1.requestBody)({ content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant, { partial: true }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, models_1.Tenant]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "updateById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.put)(`${basePath}/{id}`, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Tenant PUT success', }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, (0, rest_1.requestBody)()), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, models_1.Tenant]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "replaceById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.DeleteTenant], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.del)(`${basePath}/{id}`, { security: core_1.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Tenant DELETE success', }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String]), tslib_1.__metadata("design:returntype", Promise) ], TenantController.prototype, "deleteById", null); exports.TenantController = TenantController = tslib_1.__decorate([ tslib_1.__param(0, (0, repository_1.repository)(tenant_repository_1.TenantRepository)), tslib_1.__param(1, (0, core_2.service)(services_1.OnboardingService)), tslib_1.__param(2, (0, core_2.service)(services_1.ProvisioningService)), tslib_1.__metadata("design:paramtypes", [tenant_repository_1.TenantRepository, services_1.OnboardingService, Object]) ], TenantController); //# sourceMappingURL=tenant.controller.js.map