feat: added notification service and controller
This commit is contained in:
@@ -1,4 +1,49 @@
|
||||
import { Controller } from "@nestjs/common";
|
||||
|
||||
@Controller('notification')
|
||||
export class NotificationController {}
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { NotificationService } from './providers/notification.service';
|
||||
import { CreateNotificationDto } from './DTO/create-notification.dto';
|
||||
import { UpdateNotificationDto } from './DTO/update-notification.dto';
|
||||
import { AppNotification } from './entities/notification.entity';
|
||||
|
||||
@Controller('notification')
|
||||
export class NotificationController {
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Body() dto: CreateNotificationDto,
|
||||
): Promise<AppNotification> {
|
||||
return this.notificationService.create(dto);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@Param('id') id: string,
|
||||
): Promise<AppNotification> {
|
||||
return this.notificationService.findOneOrFail(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateNotificationDto,
|
||||
): Promise<AppNotification> {
|
||||
return this.notificationService.update(id, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async remove(
|
||||
@Param('id') id: string,
|
||||
): Promise<AppNotification> {
|
||||
return this.notificationService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,36 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { NotificationRepository } from "../repositories/notification.repository";
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { NotificationRepository } from '../repositories/notification.repository';
|
||||
import { AppNotification } from '../entities/notification.entity';
|
||||
import { CreateNotificationDto } from '../DTO/create-notification.dto';
|
||||
import { Notificationmessage } from 'src/common/enums/messages.enum';
|
||||
import { UpdateNotificationDto } from '../DTO/update-notification.dto';
|
||||
|
||||
@Injectable()
|
||||
export class NotificationService {
|
||||
constructor(
|
||||
private readonly notifRepository: NotificationRepository
|
||||
) {}
|
||||
}
|
||||
constructor(private readonly notifRepository: NotificationRepository) {}
|
||||
|
||||
async create(dto: CreateNotificationDto): Promise<AppNotification> {
|
||||
const notif = this.notifRepository.create(dto);
|
||||
await this.notifRepository.save(notif);
|
||||
return notif;
|
||||
}
|
||||
|
||||
async update(id: string, dto: UpdateNotificationDto): Promise<AppNotification> {
|
||||
const notif = await this.findOneOrFail(id);
|
||||
Object.assign(notif, dto);
|
||||
return await this.notifRepository.save(notif);
|
||||
}
|
||||
|
||||
async findOneOrFail(id: string): Promise<AppNotification> {
|
||||
const notif = await this.notifRepository.findOne({ where: { id } });
|
||||
if (!notif)
|
||||
throw new NotFoundException(Notificationmessage.NOTIFICATION_NOT_FOUND);
|
||||
return notif;
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<AppNotification> {
|
||||
const notif = await this.findOneOrFail(id);
|
||||
await this.notifRepository.remove(notif);
|
||||
return notif;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user