UNPKG

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

Version:

Tenant Management microservice for SaaS control plane

258 lines 10.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContactController = 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 contact_repository_1 = require("../repositories/contact.repository"); const models_1 = require("../models"); const permissions_1 = require("../permissions"); const basePath = '/contacts'; let ContactController = class ContactController { constructor(contactRepository) { this.contactRepository = contactRepository; } async create(contact) { return this.contactRepository.create(contact); } async count(where) { return this.contactRepository.count(where); } async find(filter) { return this.contactRepository.find(filter); } async updateAll(contact, where) { return this.contactRepository.updateAll(contact, where); } async findById(id, filter) { return this.contactRepository.findById(id, filter); } async updateById(id, contact) { await this.contactRepository.updateById(id, contact); } async replaceById(id, contact) { await this.contactRepository.replaceById(id, contact); } async deleteById(id) { await this.contactRepository.deleteById(id); } }; exports.ContactController = ContactController; tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.CreateContact], }), (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: 'Contact model instance', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Contact) }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Contact, { title: 'NewContact', exclude: ['id'], }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "create", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewContact], }), (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: 'Contact model count', content: { [core_1.CONTENT_TYPE.JSON]: { schema: repository_1.CountSchema } }, }, }, }), tslib_1.__param(0, rest_1.param.where(models_1.Contact)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "count", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewContact], }), (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 Contact model instances', content: { [core_1.CONTENT_TYPE.JSON]: { schema: { type: 'array', items: (0, rest_1.getModelSchemaRef)(models_1.Contact, { includeRelations: true }), }, }, }, }, }, }), tslib_1.__param(0, rest_1.param.filter(models_1.Contact)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "find", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateContact], }), (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: 'Contact PATCH success', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Contact), }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Contact, { partial: true }), }, }, })), tslib_1.__param(1, rest_1.param.where(models_1.Contact)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [models_1.Contact, Object]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "updateAll", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewContact], }), (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: 'Contact model instance', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Contact) }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, rest_1.param.filter(models_1.Contact, { exclude: 'where' })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, Object]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "findById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateContact], }), (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: 'Contact PATCH success', content: { [core_1.CONTENT_TYPE.JSON]: { schema: (0, rest_1.getModelSchemaRef)(models_1.Contact), }, }, }, }, }), 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.Contact, { partial: true }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, models_1.Contact]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "updateById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdateContact], }), (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: 'Contact 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.Contact]), tslib_1.__metadata("design:returntype", Promise) ], ContactController.prototype, "replaceById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.DeleteContact], }), (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: 'Contact 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) ], ContactController.prototype, "deleteById", null); exports.ContactController = ContactController = tslib_1.__decorate([ tslib_1.__param(0, (0, repository_1.repository)(contact_repository_1.ContactRepository)), tslib_1.__metadata("design:paramtypes", [contact_repository_1.ContactRepository]) ], ContactController); //# sourceMappingURL=contact.controller.js.map