diff --git a/03-di/01-notification-service/providers/NotificationService.ts b/03-di/01-notification-service/providers/NotificationService.ts index a600a59..8188bde 100644 --- a/03-di/01-notification-service/providers/NotificationService.ts +++ b/03-di/01-notification-service/providers/NotificationService.ts @@ -1 +1,10 @@ -export class NotificationService {} +import { Injectable } from "@nestjs/common"; + +@Injectable() +export class NotificationService { + constructor() {} + + sendEmail(email: string, subject: string, message: string) {} + + sendSMS(phone: string, message: string) {} +} diff --git a/03-di/01-notification-service/tasks/tasks.module.ts b/03-di/01-notification-service/tasks/tasks.module.ts index 0f9774b..cbff700 100644 --- a/03-di/01-notification-service/tasks/tasks.module.ts +++ b/03-di/01-notification-service/tasks/tasks.module.ts @@ -7,6 +7,6 @@ import { NotificationService } from "../providers/NotificationService"; @Module({ imports: [], controllers: [TasksController], - providers: [TasksService], + providers: [TasksService, NotificationService], }) export class TasksModule {} diff --git a/03-di/01-notification-service/tasks/tasks.service.ts b/03-di/01-notification-service/tasks/tasks.service.ts index 5c81948..f54c2a3 100644 --- a/03-di/01-notification-service/tasks/tasks.service.ts +++ b/03-di/01-notification-service/tasks/tasks.service.ts @@ -1,14 +1,24 @@ import { Injectable, NotFoundException } from "@nestjs/common"; import { CreateTaskDto, Task, TaskStatus, UpdateTaskDto } from "./task.model"; +import { NotificationService } from "../providers/NotificationService"; @Injectable() export class TasksService { private tasks: Task[] = []; - constructor() {} + constructor(private readonly notificationService: NotificationService) {} async createTask(createTaskDto: CreateTaskDto) { const { title, description, assignedTo } = createTaskDto; + + if (title && description && assignedTo) { + this.notificationService.sendEmail( + "user1@mail.com", + "Новая задача", + 'Вы назначены ответственным за задачу: "New Task"', + ); + } + const task: Task = { id: (this.tasks.length + 1).toString(), title, @@ -27,6 +37,13 @@ export class TasksService { throw new NotFoundException(`Задача с ID ${id} не найдена`); } + if (id && updateTaskDto.status === TaskStatus.Completed) { + this.notificationService.sendSMS( + "+987654321", + 'Статус задачи "Existing Task" обновлён на "completed"', + ); + } + Object.assign(task, updateTaskDto); return task; } diff --git a/package.json b/package.json index 6290711..518bb2d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@nestjs/swagger": "^8.1.0", "@nestjs/typeorm": "^10.0.2", + "class-validator": "^0.14.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "sqlite3": "^5.1.7",