add push settings
This commit is contained in:
@@ -5,7 +5,7 @@ import { firstValueFrom } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { CoreGrpcService } from '../core-grpc.service';
|
||||
import { getAuthorizedUserId } from '../document-access';
|
||||
import { MarkNotificationReadDto } from '../dto/notifications.dto';
|
||||
import { MarkNotificationReadDto, RegisterPushTokenDto, UnregisterPushTokenDto } from '../dto/notifications.dto';
|
||||
|
||||
@ApiTags('Уведомления')
|
||||
@ApiBearerAuth()
|
||||
@@ -83,4 +83,36 @@ export class NotificationsController {
|
||||
const userId = await getAuthorizedUserId(this.jwt, this.core, authorization);
|
||||
return firstValueFrom(this.core.notifications.DeleteAllNotifications({ userId }));
|
||||
}
|
||||
|
||||
@Post('push/register')
|
||||
@ApiOperation({ summary: 'Зарегистрировать FCM-токен устройства' })
|
||||
async registerPushToken(
|
||||
@Headers('authorization') authorization: string | undefined,
|
||||
@Body() dto: RegisterPushTokenDto
|
||||
) {
|
||||
const userId = await getAuthorizedUserId(this.jwt, this.core, authorization);
|
||||
return firstValueFrom(
|
||||
this.core.notifications.RegisterPushToken({
|
||||
userId,
|
||||
token: dto.token,
|
||||
platform: dto.platform ?? 'WEB',
|
||||
deviceLabel: dto.deviceLabel
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Delete('push/register')
|
||||
@ApiOperation({ summary: 'Удалить FCM-токен устройства' })
|
||||
async unregisterPushToken(
|
||||
@Headers('authorization') authorization: string | undefined,
|
||||
@Body() dto: UnregisterPushTokenDto
|
||||
) {
|
||||
const userId = await getAuthorizedUserId(this.jwt, this.core, authorization);
|
||||
return firstValueFrom(
|
||||
this.core.notifications.UnregisterPushToken({
|
||||
userId,
|
||||
token: dto.token
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,14 @@ export class SettingsController {
|
||||
return this.core.settings.TestMessagingDelivery({ channel: dto.channel, target: dto.target });
|
||||
}
|
||||
|
||||
@Post('firebase/test')
|
||||
@ApiOperation({ summary: 'Тест Firebase Push', description: 'Отправляет тестовое push-уведомление на устройства текущего администратора.' })
|
||||
@ApiResponse({ status: 200, description: 'Тестовое push-уведомление отправлено' })
|
||||
testFirebasePush(@CurrentAdmin() admin: AdminRequestUser) {
|
||||
assertAdminPermission(admin, 'canManageSettings');
|
||||
return this.core.settings.TestFirebasePush({ userId: admin.id });
|
||||
}
|
||||
|
||||
@Get('linked-accounts/users/:userId')
|
||||
@ApiOperation({ summary: 'Связанные внешние аккаунты', description: 'Возвращает LinkedAccount записи пользователя для Google/Yandex и других провайдеров.' })
|
||||
@ApiParam({ name: 'userId', description: 'ID пользователя' })
|
||||
|
||||
@@ -1 +1,28 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IsIn, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class MarkNotificationReadDto {}
|
||||
|
||||
export class RegisterPushTokenDto {
|
||||
@ApiProperty({ description: 'FCM-токен устройства' })
|
||||
@IsString({ message: 'FCM-токен должен быть строкой' })
|
||||
@IsNotEmpty({ message: 'Укажите FCM-токен' })
|
||||
token!: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Платформа устройства', enum: ['WEB', 'ANDROID', 'IOS'], default: 'WEB' })
|
||||
@IsOptional()
|
||||
@IsIn(['WEB', 'ANDROID', 'IOS'], { message: 'Платформа должна быть WEB, ANDROID или IOS' })
|
||||
platform?: 'WEB' | 'ANDROID' | 'IOS';
|
||||
|
||||
@ApiPropertyOptional({ description: 'Метка устройства для отладки' })
|
||||
@IsOptional()
|
||||
@IsString({ message: 'Метка устройства должна быть строкой' })
|
||||
deviceLabel?: string;
|
||||
}
|
||||
|
||||
export class UnregisterPushTokenDto {
|
||||
@ApiProperty({ description: 'FCM-токен устройства' })
|
||||
@IsString({ message: 'FCM-токен должен быть строкой' })
|
||||
@IsNotEmpty({ message: 'Укажите FCM-токен' })
|
||||
token!: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user