Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 3 task #3

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion 03-di/01-notification-service/providers/NotificationService.ts
Original file line number Diff line number Diff line change
@@ -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) {}
}
2 changes: 1 addition & 1 deletion 03-di/01-notification-service/tasks/tasks.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { NotificationService } from "../providers/NotificationService";
@Module({
imports: [],
controllers: [TasksController],
providers: [TasksService],
providers: [TasksService, NotificationService],
})
export class TasksModule {}
19 changes: 18 additions & 1 deletion 03-di/01-notification-service/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading