UNPKG

@dbbs/strapi-stripe-payment

Version:
23 lines (22 loc) 1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const http_errors_1 = __importDefault(require("http-errors")); const checkSubscriptionOwnerMiddleware = async (ctx, next) => { const userId = ctx.state.user.id; const subscriptionId = ctx.params.id; const subscription = await strapi.query('plugin::stripe-payment.subscription').findOne({ where: { id: subscriptionId }, populate: ['organization'] }); if (!subscription) { throw new http_errors_1.default.NotFound(`Subscription with ID ${subscriptionId} not found`); } if (subscription.organization.owner_id !== userId.toString()) { throw new http_errors_1.default.Forbidden('User is not the owner of the organization related to this subscription'); } await next(); }; exports.default = checkSubscriptionOwnerMiddleware;