UNPKG

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

Version:

Tenant Management microservice for SaaS control plane

309 lines 12.1 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeadController = void 0; const tslib_1 = require("tslib"); const core_1 = require("@loopback/core"); const repository_1 = require("@loopback/repository"); 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 models_1 = require("../models"); const permissions_1 = require("../permissions"); const repositories_1 = require("../repositories"); const services_1 = require("../services"); const loopback4_ratelimiter_1 = require("loopback4-ratelimiter"); const keys_1 = require("../keys"); const verify_lead_response_dto_model_1 = require("../models/dtos/verify-lead-response-dto.model"); const basePath = '/leads'; const leadDescription = 'Lead model instance'; let LeadController = class LeadController { constructor(leadRepository, onboarding, request) { this.leadRepository = leadRepository; this.onboarding = onboarding; this.request = request; } async create(lead) { return this.onboarding.addLead(lead); } async validateLead(id, leadUser) { if (leadUser.id !== id) { throw new rest_1.HttpErrors.Unauthorized(); } await this.leadRepository.updateById(leadUser.id, { isValidated: true, }); return new verify_lead_response_dto_model_1.VerifyLeadResponseDTO({ id: leadUser.id, token: leadUser.token, }); } async count(where) { return this.leadRepository.count(where); } async find(filter) { return this.leadRepository.find(filter); } async updateAll(lead, where) { throw rest_1.HttpErrors.MethodNotAllowed(); } async findById(id, filter) { return this.leadRepository.findById(id, filter); } async updateById(id, lead) { throw rest_1.HttpErrors.MethodNotAllowed(); } async replaceById(id, lead) { throw new rest_1.HttpErrors.MethodNotAllowed(); } async deleteById(id) { throw rest_1.HttpErrors.MethodNotAllowed(); } }; exports.LeadController = LeadController; 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, rest_1.post)(basePath, { responses: { [200 /* STATUS_CODE.OK */]: { description: leadDescription, content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Lead) }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.CreateLeadDTO, { title: 'CreateLeadDTO', exclude: ['isValidated', 'addressId', 'id'], }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "create", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: ['*'], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }, undefined, keys_1.LEAD_TOKEN_VERIFIER), (0, rest_1.post)(`${basePath}/{id}/verify`, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'A response with token for the verified lead', content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(verify_lead_response_dto_model_1.VerifyLeadResponseDTO), }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, (0, core_1.inject)(loopback4_authentication_1.AuthenticationBindings.CURRENT_USER)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, Object]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "validateLead", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.get)(`${basePath}/count`, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Lead model count', content: { [core_2.CONTENT_TYPE.JSON]: { schema: repository_1.CountSchema } }, }, }, }), tslib_1.__param(0, rest_1.param.where(models_1.Lead)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "count", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.get)(basePath, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Array of Lead model instances', content: { [core_2.CONTENT_TYPE.JSON]: { schema: { type: 'array', items: (0, rest_1.getModelSchemaRef)(models_1.Lead, { includeRelations: true }), }, }, }, }, }, }), tslib_1.__param(0, rest_1.param.filter(models_1.Lead)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "find", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.patch)(basePath, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: 'Lead PATCH success', content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Lead), }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Lead, { partial: true }), }, }, })), tslib_1.__param(1, rest_1.param.where(models_1.Lead)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [models_1.Lead, Object]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "updateAll", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.get)(`${basePath}/{id}`, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [200 /* STATUS_CODE.OK */]: { description: leadDescription, content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Lead) }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, rest_1.param.filter(models_1.Lead, { exclude: 'where' })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, Object]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "findById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.patch)(`${basePath}/{id}`, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Lead PATCH success', content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Lead), }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, (0, rest_1.requestBody)({ content: { [core_2.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Lead, { partial: true }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, models_1.Lead]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "updateById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.put)(`${basePath}/{id}`, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Lead 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.Lead]), tslib_1.__metadata("design:returntype", Promise) ], LeadController.prototype, "replaceById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.DeleteLead], }), (0, loopback4_authentication_1.authenticate)("bearer" /* STRATEGY.BEARER */, { passReqToCallback: true, }), (0, rest_1.del)(`${basePath}/{id}`, { security: core_2.OPERATION_SECURITY_SPEC, responses: { [204 /* STATUS_CODE.NO_CONTENT */]: { description: 'Lead 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) ], LeadController.prototype, "deleteById", null); exports.LeadController = LeadController = tslib_1.__decorate([ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.LeadRepository)), tslib_1.__param(1, (0, core_1.service)(services_1.OnboardingService)), tslib_1.__param(2, (0, core_1.inject)(rest_1.RestBindings.Http.REQUEST)), tslib_1.__metadata("design:paramtypes", [repositories_1.LeadRepository, services_1.OnboardingService, Request]) ], LeadController); //# sourceMappingURL=lead.controller.js.map