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

add solution for 3-module 1-task #4

Merged
merged 1 commit 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
16 changes: 15 additions & 1 deletion 03-di/01-notification-service/providers/NotificationService.ts
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
export class NotificationService {}
import {Injectable} from "@nestjs/common";

@Injectable()
export class NotificationService {

sendEmail(email:string, messageTheme: string, message: string) {
const logMessage = `Email sent to ${email}: [${messageTheme}] ${message}`;
console.log(logMessage)
}

sendSMS(phone: string, message:string) {
const logMessage = `SMS sent to ${phone}: ${message}`;
console.log(logMessage)
}
}
4 changes: 2 additions & 2 deletions 03-di/01-notification-service/tasks/tasks.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { UsersModule } from "../users/users.module";
import { NotificationService } from "../providers/NotificationService";

@Module({
imports: [],
imports: [UsersModule],
controllers: [TasksController],
providers: [TasksService],
providers: [TasksService, NotificationService],
})
export class TasksModule {}
16 changes: 15 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,21 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { CreateTaskDto, Task, TaskStatus, UpdateTaskDto } from "./task.model";
import {NotificationService} from "../providers/NotificationService";
import {UsersService} from "../users/users.service";

@Injectable()
export class TasksService {
private tasks: Task[] = [];

constructor() {}
constructor(
private readonly notificationService: NotificationService,
private readonly userService: UsersService
) {}

async createTask(createTaskDto: CreateTaskDto) {
const { title, description, assignedTo } = createTaskDto;
const user = this.userService.getUserById(assignedTo);

const task: Task = {
id: (this.tasks.length + 1).toString(),
title,
Expand All @@ -18,6 +25,9 @@ export class TasksService {
};
this.tasks.push(task);

const notificationMessage = `Вы назначены ответственным за задачу: "${task.title}"`;
this.notificationService.sendEmail(user.email, 'Новая задача', notificationMessage)

return task;
}

Expand All @@ -26,8 +36,12 @@ export class TasksService {
if (!task) {
throw new NotFoundException(`Задача с ID ${id} не найдена`);
}
const user = this.userService.getUserById(task.assignedTo);

Object.assign(task, updateTaskDto);
const notificationMessage = `Статус задачи "${task.title}" обновлён на "${task.status}"`;
this.notificationService.sendSMS(user.phone, notificationMessage);

return task;
}
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
"@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",
"@types/lodash": "^4.17.13",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"lodash": "^4.17.21",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"sqlite3": "^5.1.7",
"typeorm": "^0.3.20",
"@types/lodash": "^4.17.13",
"lodash": "^4.17.21"
"typeorm": "^0.3.20"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
Loading