This commit is contained in:
2025-12-13 11:14:18 +03:30
parent 3eb6b889a4
commit c25a5afe01
80 changed files with 440 additions and 190 deletions
@@ -21,7 +21,14 @@ export class NotificationsController {
@ApiBearerAuth()
@Get('public/notifications')
@ApiOperation({ summary: 'Get user restaurant notifications' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiHeader({
name: 'X-Slug',
required: true,
schema: {
type: 'string',
default: 'zhivan',
},
})
@ApiQuery({ name: 'limit', required: false, type: Number })
async getUserNotifications(@UserId() userId: string, @RestId() restaurantId: string, @Query('limit') limit?: number) {
return await this.notificationService.findByUserAndRestaurant(
@@ -1,5 +1,6 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { AuthenticatedSocket } from '../guards/ws-admin-auth.guard';
import type { ExecutionContext } from '@nestjs/common';
import { createParamDecorator } from '@nestjs/common';
import type { AuthenticatedSocket } from '../guards/ws-admin-auth.guard';
/**
* Extract restaurant ID from authenticated WebSocket client
@@ -38,4 +38,3 @@ export class CreateNotificationDto {
@IsOptional()
data?: Record<string, any>;
}
@@ -28,7 +28,7 @@ export class PushNotificationService {
private initializeFirebase() {
try {
const firebaseConfig = this.configService.get<string>('FIREBASE_SERVICE_ACCOUNT');
if (!firebaseConfig) {
this.logger.warn('Firebase service account not configured. Push notifications will be disabled.');
return;
@@ -51,7 +51,10 @@ export class PushNotificationService {
async sendToToken(payload: PushNotificationPayload): Promise<PushNotificationResponse> {
if (!this.firebaseApp || !payload.token) {
throw new HttpException('Push notification service not configured or token missing', HttpStatus.SERVICE_UNAVAILABLE);
throw new HttpException(
'Push notification service not configured or token missing',
HttpStatus.SERVICE_UNAVAILABLE,
);
}
try {
@@ -115,9 +118,7 @@ export class PushNotificationService {
};
const response = await admin.messaging().sendEachForMulticast(message);
this.logger.log(
`Push notifications sent: ${response.successCount} successful, ${response.failureCount} failed`,
);
this.logger.log(`Push notifications sent: ${response.successCount} successful, ${response.failureCount} failed`);
return {
success: response.successCount > 0,
@@ -145,4 +146,3 @@ export class PushNotificationService {
return this.firebaseApp !== null;
}
}