Files
ulitka/src/modules/notification/infrastructure/senders/push-channel.sender.ts
T
2026-09-29 18:42:29 +03:00

32 lines
1.5 KiB
TypeScript

import { Inject, Injectable, Logger } from '@nestjs/common';
import type { NotificationChannelSender } from '../../domain/channel-sender.interface.js';
import type { NotificationChannelValue } from '../../domain/value-objects/notification-channel.vo.js';
import {
DEVICE_TOKEN_REPOSITORY,
type IDeviceTokenRepository,
} from '../../domain/repositories/device-token.repository.interface.js';
/**
* Провайдер push-доставки (FCM/APNs) пока не подключён — отправка логируется.
* Токены уже читаются из БД, так что при подключении провайдера
* меняется только тело send(), остальной пайплайн трогать не нужно.
*/
@Injectable()
export class PushChannelSender implements NotificationChannelSender {
private readonly logger = new Logger(PushChannelSender.name);
readonly channel: NotificationChannelValue = 'PUSH';
constructor(@Inject(DEVICE_TOKEN_REPOSITORY) private readonly deviceTokens: IDeviceTokenRepository) {}
async send(params: { userId: string; content: string }): Promise<void> {
const tokens = await this.deviceTokens.findByUserId(params.userId);
if (tokens.length === 0) {
throw new Error(`No device tokens registered for user ${params.userId}`);
}
this.logger.warn(
`Push provider is not configured yet, skipping actual delivery to ${tokens.length} device(s): ${params.content}`,
);
}
}