diff --git a/notification-service/src/main.ts b/notification-service/src/main.ts index c5a42b5..6b2dc83 100644 --- a/notification-service/src/main.ts +++ b/notification-service/src/main.ts @@ -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}`); } } } diff --git a/request.http b/request.http index 91d46c5..6c12383 100644 --- a/request.http +++ b/request.http @@ -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 diff --git a/todo-service/src/controllers/todoController.ts b/todo-service/src/controllers/todoController.ts index 8dc8dab..320ea70 100644 --- a/todo-service/src/controllers/todoController.ts +++ b/todo-service/src/controllers/todoController.ts @@ -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); };