/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
apps/api/src/app/contexts/usecases/create-context/create-context.usecase.ts
43 строки
2 KB
Dima Grossman
feat(api-service): context-scoped bridge URL override for agent connect fixes NV-8582 (#12319)
12 авг 2026, 15:03
Не верифицирован
12 авг 2026, 15:03
5f553b4
Код
Авторство
О чём код?
import { ConflictException, Injectable } from '@nestjs/common'; import { ContextEntity, ContextRepository, isDuplicateKeyError } from '@novu/dal'; import { createContextKey } from '@novu/shared'; import { assertSafeContextBridgeUrl } from '../assert-safe-context-bridge-url'; import { CreateContextCommand } from './create-context.command'; @Injectable() export class CreateContext { constructor(private contextRepository: ContextRepository) {} async execute(command: CreateContextCommand): Promise<ContextEntity> { await assertSafeContextBridgeUrl(command.bridgeUrl); const existingContext = await this.contextRepository.findOne({ _environmentId: command.environmentId, _organizationId: command.organizationId, type: command.type, id: command.id, }); if (existingContext) { throw new ConflictException(`Context with type '${command.type}' and id '${command.id}' already exists`); } try { return await this.contextRepository.create({ _environmentId: command.environmentId, _organizationId: command.organizationId, type: command.type, id: command.id, key: createContextKey(command.type, command.id), data: command.data || {}, ...(command.bridgeUrl ? { bridgeUrl: command.bridgeUrl } : {}), }); } catch (error) { if (isDuplicateKeyError(error)) { throw new ConflictException(`Context with type '${command.type}' and id '${command.id}' already exists`); } throw error; } } }