@dbbs/strapi-stripe-payment
Version:
Strapi integration plugin for Stripe payment system
23 lines (22 loc) • 956 B
JavaScript
;
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 checkOrganizationOwnerMiddleware = async (ctx, next) => {
const userId = ctx.state.user.id;
const organizationId = ctx.params.id;
const organization = await strapi.query('plugin::stripe-payment.organization').findOne({
where: { id: organizationId },
select: ['owner_id']
});
if (!organization) {
throw new http_errors_1.default.NotFound(`Organization with ID ${organizationId} not found`);
}
if (organization.owner_id !== userId.toString()) {
throw new http_errors_1.default.Forbidden('User is not the owner of this organization');
}
await next();
};
exports.default = checkOrganizationOwnerMiddleware;