UNPKG

@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

47 lines 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WebhookUsersService = void 0; const tslib_1 = require("tslib"); const prisma_1 = require("@nestjs-mod/prisma"); const common_1 = require("@nestjs/common"); const omit_1 = tslib_1.__importDefault(require("lodash/fp/omit")); const node_crypto_1 = require("node:crypto"); const prisma_client_1 = require("../generated/prisma-client"); const webhook_constants_1 = require("../webhook.constants"); let WebhookUsersService = class WebhookUsersService { constructor(prismaClient) { this.prismaClient = prismaClient; } async createUserIfNotExists(user) { const data = { externalTenantId: (0, node_crypto_1.randomUUID)(), userRole: prisma_client_1.WebhookRole.User, ...(0, omit_1.default)([ 'id', 'createdAt', 'updatedAt', 'Webhook_Webhook_createdByToWebhookUser', 'Webhook_Webhook_updatedByToWebhookUser', ], user), }; const existsUser = await this.prismaClient.webhookUser.findFirst({ where: { externalTenantId: user.externalTenantId, externalUserId: user.externalUserId, }, }); if (!existsUser) { return await this.prismaClient.webhookUser.create({ data, }); } return existsUser; } }; exports.WebhookUsersService = WebhookUsersService; exports.WebhookUsersService = WebhookUsersService = tslib_1.__decorate([ (0, common_1.Injectable)(), tslib_1.__param(0, (0, prisma_1.InjectPrismaClient)(webhook_constants_1.WEBHOOK_FEATURE)), tslib_1.__metadata("design:paramtypes", [prisma_client_1.PrismaClient]) ], WebhookUsersService); //# sourceMappingURL=webhook-users.service.js.map