adding business logic

This commit is contained in:
Kfir Dayan 2023-07-09 01:34:20 +03:00
parent b26eef9b2c
commit ad9a796c7a
3 changed files with 7 additions and 15 deletions

View file

@ -1,6 +1,5 @@
import { ITodo } from "./interfaces/ITodo";
import { RabbitMQ } from "./rabbitmq/RabbitMQ";
import { EnvService } from "./services/EnvService";
import { MongoDbModel } from "./mongodb/MongoDb";
export class NotificationService {
@ -21,22 +20,12 @@ export class NotificationService {
}
async newMessageValidator(message: ITodo) {
console.log("Validating message:", message)
const todo = await this.mongoModle.getTodoById(message._id.toString());
console.log("Todo:", todo)
if (todo) {
const due_date = new Date(todo.due_date);
if (
todo.status === "pending" &&
due_date > new Date()
) {
if (todo.status === "pending" && due_date > new Date()) {
await this.mongoModle.updateTodoStatus(todo);
await this.sendNotification(todo); // Send notification to user
} else {
console.log("Todo is not valid for notification");
console.log(`todo.status === "pending" - ${todo.status === "pending"}`);
console.log(`todo.due_date < new Date() - ${todo.due_date < new Date()}`);
console.log(`todo.due_date === message.due_date - ${todo.due_date === message.due_date}`);
}
}
}

View file

@ -13,13 +13,13 @@ Content-Type: application/json
}
### update request
PUT http://localhost:3000/todo/{ID}
PUT http://localhost:3000/todo/64a9e3987a2dba152b1e44b0
Content-Type: application/json
{
"title": "test",
"description": "TEST NEW!",
"due_date": "2020-12-12"
"due_date": "2023-07-09T19:00:00.891Z"
}
### delete *ALL* request

View file

@ -40,7 +40,7 @@ export class TodoController {
if (todo instanceof ApiError) {
return next(todo);
}
this.queue.create(todo);
await this.queue.create(todo);
return res.json(todo);
} catch {
@ -65,6 +65,9 @@ export class TodoController {
if (todo instanceof ApiError) {
return next(todo);
}
await this.queue.create(todo);
return res.json(todo);
};