Template base para proyectos SaaS multi-tenant. Estructura inicial: - apps/backend (NestJS API) - apps/frontend (React/Vite) - apps/database (PostgreSQL DDL) - docs/ (Documentación) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
235 lines
11 KiB
JavaScript
235 lines
11 KiB
JavaScript
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.BillingController = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const swagger_1 = require("@nestjs/swagger");
|
|
const billing_service_1 = require("./services/billing.service");
|
|
const dto_1 = require("./dto");
|
|
const jwt_auth_guard_1 = require("../auth/guards/jwt-auth.guard");
|
|
const permissions_guard_1 = require("../rbac/guards/permissions.guard");
|
|
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
|
|
let BillingController = class BillingController {
|
|
constructor(billingService) {
|
|
this.billingService = billingService;
|
|
}
|
|
async getSubscription(user) {
|
|
return this.billingService.getSubscription(user.tenant_id);
|
|
}
|
|
async getSubscriptionStatus(user) {
|
|
return this.billingService.checkSubscriptionStatus(user.tenant_id);
|
|
}
|
|
async createSubscription(dto, user) {
|
|
dto.tenant_id = user.tenant_id;
|
|
return this.billingService.createSubscription(dto);
|
|
}
|
|
async updateSubscription(dto, user) {
|
|
return this.billingService.updateSubscription(user.tenant_id, dto);
|
|
}
|
|
async cancelSubscription(dto, user) {
|
|
return this.billingService.cancelSubscription(user.tenant_id, dto);
|
|
}
|
|
async changePlan(planId, user) {
|
|
return this.billingService.changePlan(user.tenant_id, planId);
|
|
}
|
|
async getInvoices(user, page, limit) {
|
|
return this.billingService.getInvoices(user.tenant_id, { page, limit });
|
|
}
|
|
async getInvoice(id, user) {
|
|
return this.billingService.getInvoice(id, user.tenant_id);
|
|
}
|
|
async markInvoicePaid(id, user) {
|
|
return this.billingService.markInvoicePaid(id, user.tenant_id);
|
|
}
|
|
async voidInvoice(id, user) {
|
|
return this.billingService.voidInvoice(id, user.tenant_id);
|
|
}
|
|
async getPaymentMethods(user) {
|
|
return this.billingService.getPaymentMethods(user.tenant_id);
|
|
}
|
|
async addPaymentMethod(dto, user) {
|
|
return this.billingService.addPaymentMethod(user.tenant_id, dto);
|
|
}
|
|
async setDefaultPaymentMethod(id, user) {
|
|
return this.billingService.setDefaultPaymentMethod(id, user.tenant_id);
|
|
}
|
|
async removePaymentMethod(id, user) {
|
|
await this.billingService.removePaymentMethod(id, user.tenant_id);
|
|
return { message: 'Payment method removed' };
|
|
}
|
|
async getBillingSummary(user) {
|
|
return this.billingService.getBillingSummary(user.tenant_id);
|
|
}
|
|
};
|
|
exports.BillingController = BillingController;
|
|
__decorate([
|
|
(0, common_1.Get)('subscription'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get current subscription' }),
|
|
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "getSubscription", null);
|
|
__decorate([
|
|
(0, common_1.Get)('subscription/status'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Check subscription status' }),
|
|
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "getSubscriptionStatus", null);
|
|
__decorate([
|
|
(0, common_1.Post)('subscription'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Create subscription (admin)' }),
|
|
__param(0, (0, common_1.Body)()),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [dto_1.CreateSubscriptionDto, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "createSubscription", null);
|
|
__decorate([
|
|
(0, common_1.Patch)('subscription'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Update subscription' }),
|
|
__param(0, (0, common_1.Body)()),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [dto_1.UpdateSubscriptionDto, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "updateSubscription", null);
|
|
__decorate([
|
|
(0, common_1.Post)('subscription/cancel'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Cancel subscription' }),
|
|
__param(0, (0, common_1.Body)()),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [dto_1.CancelSubscriptionDto, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "cancelSubscription", null);
|
|
__decorate([
|
|
(0, common_1.Post)('subscription/change-plan/:planId'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Change subscription plan' }),
|
|
__param(0, (0, common_1.Param)('planId')),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "changePlan", null);
|
|
__decorate([
|
|
(0, common_1.Get)('invoices'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get invoices' }),
|
|
(0, swagger_1.ApiQuery)({ name: 'page', required: false, type: Number }),
|
|
(0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }),
|
|
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
__param(1, (0, common_1.Query)('page')),
|
|
__param(2, (0, common_1.Query)('limit')),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object, Number, Number]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "getInvoices", null);
|
|
__decorate([
|
|
(0, common_1.Get)('invoices/:id'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get invoice by ID' }),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "getInvoice", null);
|
|
__decorate([
|
|
(0, common_1.Post)('invoices/:id/mark-paid'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Mark invoice as paid (admin)' }),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "markInvoicePaid", null);
|
|
__decorate([
|
|
(0, common_1.Post)('invoices/:id/void'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Void invoice (admin)' }),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "voidInvoice", null);
|
|
__decorate([
|
|
(0, common_1.Get)('payment-methods'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get payment methods' }),
|
|
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "getPaymentMethods", null);
|
|
__decorate([
|
|
(0, common_1.Post)('payment-methods'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Add payment method' }),
|
|
__param(0, (0, common_1.Body)()),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [dto_1.CreatePaymentMethodDto, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "addPaymentMethod", null);
|
|
__decorate([
|
|
(0, common_1.Post)('payment-methods/:id/set-default'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Set default payment method' }),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "setDefaultPaymentMethod", null);
|
|
__decorate([
|
|
(0, common_1.Delete)('payment-methods/:id'),
|
|
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
|
|
(0, permissions_guard_1.RequirePermissions)('billing:manage'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Remove payment method' }),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__param(1, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "removePaymentMethod", null);
|
|
__decorate([
|
|
(0, common_1.Get)('summary'),
|
|
(0, swagger_1.ApiOperation)({ summary: 'Get billing summary' }),
|
|
__param(0, (0, current_user_decorator_1.CurrentUser)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [Object]),
|
|
__metadata("design:returntype", Promise)
|
|
], BillingController.prototype, "getBillingSummary", null);
|
|
exports.BillingController = BillingController = __decorate([
|
|
(0, swagger_1.ApiTags)('billing'),
|
|
(0, common_1.Controller)('billing'),
|
|
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
|
|
(0, swagger_1.ApiBearerAuth)(),
|
|
__metadata("design:paramtypes", [billing_service_1.BillingService])
|
|
], BillingController);
|
|
//# sourceMappingURL=billing.controller.js.map
|