@nestjs-mod/webhook
Version:
Webhook module with an error filter, guard, controller, database migrations and rest-sdk for work with module from other nodejs appliaction
30 lines • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CurrentWebhookExternalTenantId = exports.CurrentWebhookUser = exports.CurrentWebhookRequest = exports.CheckWebhookRole = exports.InjectWebhookFeatures = void 0;
const common_1 = require("@nestjs-mod/common");
const common_2 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
const prisma_client_1 = require("./generated/prisma-client");
const webhook_constants_1 = require("./webhook.constants");
const webhook_errors_1 = require("./webhook.errors");
exports.InjectWebhookFeatures = (0, common_1.getNestModuleDecorators)({
moduleName: webhook_constants_1.WEBHOOK_MODULE,
}).InjectFeatures;
exports.CheckWebhookRole = core_1.Reflector.createDecorator();
exports.CurrentWebhookRequest = (0, common_2.createParamDecorator)((_data, ctx) => {
const req = (0, common_1.getRequestFromExecutionContext)(ctx);
return req;
});
exports.CurrentWebhookUser = (0, common_2.createParamDecorator)((_data, ctx) => {
const req = (0, common_1.getRequestFromExecutionContext)(ctx);
return req.webhookUser;
});
exports.CurrentWebhookExternalTenantId = (0, common_2.createParamDecorator)((_data, ctx) => {
const req = (0, common_1.getRequestFromExecutionContext)(ctx);
if (!req.externalTenantId &&
req.webhookUser?.userRole !== prisma_client_1.WebhookRole.Admin) {
throw new webhook_errors_1.WebhookError(webhook_errors_1.WebhookErrorEnum.EXTERNAL_TENANT_ID_NOT_SET);
}
return req.externalTenantId;
});
//# sourceMappingURL=webhook.decorators.js.map