UNPKG

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

Version:

Tenant Management microservice for SaaS control plane

73 lines 3.15 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeadTenantController = void 0; const tslib_1 = require("tslib"); const core_1 = require("@loopback/core"); const rest_1 = require("@loopback/rest"); const core_2 = require("@sourceloop/core"); const loopback4_authentication_1 = require("loopback4-authentication"); const loopback4_authorization_1 = require("loopback4-authorization"); const services_1 = require("../services"); const models_1 = require("../models"); const loopback4_ratelimiter_1 = require("loopback4-ratelimiter"); const basePath = '/leads/{id}/tenants'; let LeadTenantController = class LeadTenantController { constructor(onboardingService, logger) { this.onboardingService = onboardingService; this.logger = logger; } async tenantFromLead(leadUser, dto, id) { if (leadUser.id !== id) { this.logger.error('Lead id does not match with the id in token'); throw new rest_1.HttpErrors.Unauthorized(); } return this.onboardingService.onboardForLead(dto, leadUser); } }; exports.LeadTenantController = LeadTenantController; tslib_1.__decorate([ (0, loopback4_ratelimiter_1.ratelimit)(true, { max: parseInt((_a = process.env.PUBLIC_API_MAX_ATTEMPTS) !== null && _a !== void 0 ? _a : '10'), keyGenerator: core_2.rateLimitKeyGenPublic, }), (0, loopback4_authorization_1.authorize)({ permissions: ['*'], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.post)(basePath, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Tenant model instance', content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Tenant) }, }, }, }, }), tslib_1.__param(0, (0, core_1.inject)(loopback4_authentication_1.AuthenticationBindings.CURRENT_USER)), tslib_1.__param(1, (0, rest_1.requestBody)({ content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.TenantOnboardDTO, { title: 'TenantOnboardDto', exclude: ['contact'], optional: ['name'], }), }, }, })), tslib_1.__param(2, rest_1.param.path.string('id')), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object, Object, String]), tslib_1.__metadata("design:returntype", Promise) ], LeadTenantController.prototype, "tenantFromLead", null); exports.LeadTenantController = LeadTenantController = tslib_1.__decorate([ tslib_1.__param(0, (0, core_1.service)(services_1.OnboardingService)), tslib_1.__param(1, (0, core_1.inject)(core_2.LOGGER.LOGGER_INJECT)), tslib_1.__metadata("design:paramtypes", [services_1.OnboardingService, Object]) ], LeadTenantController); //# sourceMappingURL=lead-tenant.controller.js.map