notification
This commit is contained in:
1 parent
382cafa152
commit
60391ee123
26 files changed
+1077
-14
No files matched your search
@@ -0,0 +1,31 @@
|
||||
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}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user