UNPKG

@sourceloop/ctrl-plane-subscription-service

Version:

Subscription management microservice for SaaS control plane.

251 lines 9.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlanController = void 0; const tslib_1 = require("tslib"); const repository_1 = require("@loopback/repository"); const rest_1 = require("@loopback/rest"); const models_1 = require("../models"); const repositories_1 = require("../repositories"); const loopback4_authorization_1 = require("loopback4-authorization"); const loopback4_authentication_1 = require("loopback4-authentication"); const permissions_1 = require("../permissions"); const core_1 = require("@sourceloop/core"); const basePath = '/plans'; let PlanController = class PlanController { constructor(planRepository) { this.planRepository = planRepository; } async create(plan) { return this.planRepository.create(plan); } async count(where) { return this.planRepository.count(where); } async find(filter) { return this.planRepository.find(filter); } async updateAll(plan, where) { return this.planRepository.updateAll(plan, where); } async findById(id, filter) { return this.planRepository.findById(id, filter); } async updateById(id, plan) { await this.planRepository.updateById(id, plan); } async replaceById(id, plan) { await this.planRepository.replaceById(id, plan); } async deleteById(id) { await this.planRepository.deleteById(id); } }; exports.PlanController = PlanController; tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.CreatePlan], }), (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: 'Plan model instance', content: { 'application/json': { schema: (0, core_1.getModelSchemaRefSF)(models_1.Plan) }, }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { 'application/json': { schema: (0, core_1.getModelSchemaRefSF)(models_1.Plan, { title: 'NewPlan', exclude: ['id'], }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "create", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewPlan], }), (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: 'Plan model count', content: { 'application/json': { schema: repository_1.CountSchema } }, }, }, }), tslib_1.__param(0, rest_1.param.where(models_1.Plan)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "count", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewPlan], }), (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 Plan model instances', content: { 'application/json': { schema: { type: 'array', items: (0, core_1.getModelSchemaRefSF)(models_1.Plan, { includeRelations: true }), }, }, }, }, }, }), tslib_1.__param(0, rest_1.param.filter(models_1.Plan)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [Object]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "find", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdatePlan], }), (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: 'Plan PATCH success count', content: { 'application/json': { schema: repository_1.CountSchema } }, }, }, }), tslib_1.__param(0, (0, rest_1.requestBody)({ content: { 'application/json': { schema: (0, core_1.getModelSchemaRefSF)(models_1.Plan, { partial: true }), }, }, })), tslib_1.__param(1, rest_1.param.where(models_1.Plan)), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [models_1.Plan, Object]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "updateAll", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.ViewPlan], }), (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: 'Plan model instance', content: { 'application/json': { schema: (0, core_1.getModelSchemaRefSF)(models_1.Plan, { includeRelations: true }), }, }, }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, rest_1.param.filter(models_1.Plan, { exclude: 'where' })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, Object]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "findById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdatePlan], }), (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: 'Plan PATCH success', }, }, }), tslib_1.__param(0, rest_1.param.path.string('id')), tslib_1.__param(1, (0, rest_1.requestBody)({ content: { 'application/json': { schema: (0, core_1.getModelSchemaRefSF)(models_1.Plan, { partial: true }), }, }, })), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [String, models_1.Plan]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "updateById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.UpdatePlan], }), (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: 'Plan 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.Plan]), tslib_1.__metadata("design:returntype", Promise) ], PlanController.prototype, "replaceById", null); tslib_1.__decorate([ (0, loopback4_authorization_1.authorize)({ permissions: [permissions_1.PermissionKey.DeletePlan], }), (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: 'Plan 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) ], PlanController.prototype, "deleteById", null); exports.PlanController = PlanController = tslib_1.__decorate([ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.PlanRepository)), tslib_1.__metadata("design:paramtypes", [repositories_1.PlanRepository]) ], PlanController); //# sourceMappingURL=plan.controller.js.map