feat: added notification service and controller
This commit is contained in:
@@ -43,3 +43,7 @@ export const enum UploaderMessage {
|
|||||||
UPLOAD_FILE_TOO_LARGE = '[MAX_FILE_SIZE] فایل بزرگتر از حد مجاز است',
|
UPLOAD_FILE_TOO_LARGE = '[MAX_FILE_SIZE] فایل بزرگتر از حد مجاز است',
|
||||||
UPLOAD_FILE_TYPE_NOT_SUPPORTED = '[MIME_TYPES] نوع فایل مجاز نیست',
|
UPLOAD_FILE_TYPE_NOT_SUPPORTED = '[MIME_TYPES] نوع فایل مجاز نیست',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const enum Notificationmessage {
|
||||||
|
NOTIFICATION_NOT_FOUND = 'اعلان مورد نظر پیدا نشد!'
|
||||||
|
}
|
||||||
@@ -1,4 +1,49 @@
|
|||||||
import { Controller } from "@nestjs/common";
|
import {
|
||||||
|
Body,
|
||||||
@Controller('notification')
|
Controller,
|
||||||
export class NotificationController {}
|
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 { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { NotificationRepository } from "../repositories/notification.repository";
|
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()
|
@Injectable()
|
||||||
export class NotificationService {
|
export class NotificationService {
|
||||||
constructor(
|
constructor(private readonly notifRepository: NotificationRepository) {}
|
||||||
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