forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-notifications.controller.ts
More file actions
76 lines (68 loc) · 2.66 KB
/
Copy pathpush-notifications.controller.ts
File metadata and controls
76 lines (68 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Controller, Post, Body, Delete, Param, Get, Put, Req, Logger, UseGuards, BadRequestException, ForbiddenException } from '@nestjs/common';
import { PushNotificationsService } from './push-notifications.service';
import { RegisterDeviceDto } from './dto/register-device.dto';
import { UpdatePreferencesDto } from './dto/update-preferences.dto';
import { NotificationEventType } from './entities/notification-preference.entity';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
@Controller('push')
@UseGuards(JwtAuthGuard)
export class PushNotificationsController {
private readonly logger = new Logger(PushNotificationsController.name);
constructor(private readonly pushService: PushNotificationsService) {}
@Post('register-device')
async registerDevice(@Body() dto: RegisterDeviceDto, @Req() req: any) {
const userId = req.user?.walletAddress;
if (!userId) {
throw new BadRequestException('User authentication required');
}
dto.userId = userId;
return this.pushService.registerDevice(dto);
}
@Delete('unregister-device/:deviceId')
async unregisterDevice(@Param('deviceId') deviceId: string, @Req() req: any) {
const userId = req.user?.walletAddress;
if (!userId) {
throw new BadRequestException('User authentication required');
}
return this.pushService.unregisterDevice(deviceId, userId);
}
@Get('devices')
async getDevices(@Req() req: any) {
const userId = req.user?.walletAddress;
if (!userId) {
throw new BadRequestException('User authentication required');
}
return this.pushService.getDevices(userId);
}
@Put('preferences')
async updatePreferences(@Body() dto: UpdatePreferencesDto, @Req() req: any) {
const userId = req.user?.walletAddress;
if (!userId) {
throw new BadRequestException('User authentication required');
}
dto.userId = userId;
return this.pushService.updatePreferences(dto);
}
@Get('preferences')
async getPreferences(@Req() req: any) {
const userId = req.user?.walletAddress;
if (!userId) {
throw new BadRequestException('User authentication required');
}
return this.pushService.getPreferences(userId);
}
@Post('test-internal')
async sendTestNotification(@Body() body: { title?: string, message?: string }, @Req() req: any) {
const userId = req.user?.walletAddress;
if (!userId) {
throw new BadRequestException('User authentication required');
}
const { title, message } = body;
await this.pushService.sendTestNotification(
userId,
title || 'Test Notification',
message || 'This is a test notification from StellarSplit'
);
return { success: true };
}
}