Merge branch 'master' into dev
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import { Controller, Post, Get, Body, Param, UseGuards, Query, Patch, Delete } from '@nestjs/common';
|
import { Controller, Get, Body, Param, UseGuards, Query, Patch, Put } from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
|
||||||
import { NotificationService } from '../services/notification.service';
|
import { NotificationService } from '../services/notification.service';
|
||||||
import { NotificationPreferenceService } from '../services/notification-preference.service';
|
import { NotificationPreferenceService } from '../services/notification-preference.service';
|
||||||
import { CreatePreferenceDto } from '../dto/create-preference.dto';
|
|
||||||
import { AuthGuard } from '../../auth/guards/auth.guard';
|
import { AuthGuard } from '../../auth/guards/auth.guard';
|
||||||
import { UserId } from '../../../common/decorators/user-id.decorator';
|
import { UserId } from '../../../common/decorators/user-id.decorator';
|
||||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||||
import { RestId } from '../../../common/decorators/rest-id.decorator';
|
import { RestId } from '../../../common/decorators/rest-id.decorator';
|
||||||
import { UpdatePreferenceDto } from '../dto/update-preference.dto';
|
import { UpdatePreferenceDto } from '../dto/update-preference.dto';
|
||||||
|
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
||||||
|
|
||||||
@ApiTags('notifications')
|
@ApiTags('notifications')
|
||||||
@Controller()
|
@Controller()
|
||||||
@@ -38,6 +38,16 @@ export class NotificationsController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Put('public/notifications/:id')
|
||||||
|
@ApiOperation({ summary: 'Read a notification ' })
|
||||||
|
@ApiParam({ name: 'id', description: 'Notification ID' })
|
||||||
|
async readNotificationUser(@RestId() restaurantId: string, @Param('id') id: string, @UserId() userId: string) {
|
||||||
|
await this.notificationService.readNotificationAsUser(id, userId, restaurantId);
|
||||||
|
return { message: 'Notification read successfully' };
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Get('admin/notifications')
|
@Get('admin/notifications')
|
||||||
@@ -49,12 +59,12 @@ export class NotificationsController {
|
|||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Delete('admin/notification/:id')
|
@Put('admin/notifications/:id')
|
||||||
@ApiOperation({ summary: 'Delete a notification ' })
|
@ApiOperation({ summary: 'Read a notification ' })
|
||||||
@ApiParam({ name: 'id', description: 'Notification ID' })
|
@ApiParam({ name: 'id', description: 'Notification ID' })
|
||||||
async deleteNotification(@RestId() restaurantId: string, @Param('id') id: string) {
|
async readNotificationAdmin(@RestId() restaurantId: string, @AdminId() adminId: string, @Param('id') id: string) {
|
||||||
await this.notificationService.removeNotification(id, restaurantId);
|
await this.notificationService.readNotificationAdmin(id, adminId, restaurantId);
|
||||||
return { message: 'Notification deleted successfully' };
|
return { message: 'Notification read successfully' };
|
||||||
}
|
}
|
||||||
|
|
||||||
// @UseGuards(AuthGuard)
|
// @UseGuards(AuthGuard)
|
||||||
|
|||||||
@@ -119,12 +119,29 @@ export class NotificationService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeNotification(id: string, restaurantId: string): Promise<void> {
|
async readNotificationAdmin(id: string, adminId: string, restaurantId: string): Promise<void> {
|
||||||
const notification = await this.em.findOne(Notification, { id, restaurant: { id: restaurantId } });
|
const notification = await this.em.findOne(Notification, {
|
||||||
|
id,
|
||||||
|
admin: { id: adminId },
|
||||||
|
restaurant: { id: restaurantId },
|
||||||
|
});
|
||||||
if (!notification) {
|
if (!notification) {
|
||||||
throw new NotFoundException('Notification not found');
|
throw new NotFoundException('Notification not found');
|
||||||
}
|
}
|
||||||
await this.em.removeAndFlush(notification as any);
|
notification.sentAt = new Date();
|
||||||
|
await this.em.persistAndFlush(notification);
|
||||||
|
}
|
||||||
|
async readNotificationAsUser(id: string, userId: string, restaurantId: string): Promise<void> {
|
||||||
|
const notification = await this.em.findOne(Notification, {
|
||||||
|
id,
|
||||||
|
user: { id: userId },
|
||||||
|
restaurant: { id: restaurantId },
|
||||||
|
});
|
||||||
|
if (!notification) {
|
||||||
|
throw new NotFoundException('Notification not found');
|
||||||
|
}
|
||||||
|
notification.sentAt = new Date();
|
||||||
|
await this.em.persistAndFlush(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByRestaurantAndType(restaurantId: string, title: NotifTitleEnum, limit = 50): Promise<Notification[]> {
|
async findByRestaurantAndType(restaurantId: string, title: NotifTitleEnum, limit = 50): Promise<Notification[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user