fixing small bug

This commit is contained in:
Kfir Dayan 2023-07-13 11:19:22 +03:00
parent 6e34384129
commit 739f3b9913
3 changed files with 16 additions and 6 deletions

View file

@ -6,7 +6,7 @@ import { DateService } from "./services/DateService";
export class NotificationService {
rabbitmq: RabbitMQ;
mongoModel: MongoDbModel;
currentDate: any;
currentDate: DateService;
constructor() {
this.currentDate = DateService.getInstance();
@ -20,6 +20,12 @@ export class NotificationService {
if (this.IsUserConnected()) {
await this.rabbitmq.connect();
this.rabbitmq.startConsumer(this.newMessageValidator.bind(this));
} else {
// Retry in 5 seconds
setTimeout(() => {
console.log("Waiting for user to connect...")
this.startListener();
}, 5000);
}
}
@ -28,13 +34,15 @@ export class NotificationService {
const todo: ITodo | void = await this.mongoModel.getTodoById(message._id.toString());
if (todo) {
const due_date = new Date(todo.due_date);
if (todo.status === "pending" && due_date > this.currentDate.getDate()) {
if (todo.status === "pending" && due_date > this.currentDate.getCurrentDate()) {
await this.mongoModel.updateTodoStatus(todo);
await this.sendNotification(todo); // Send notification to user
}
} else {
console.error("todo Not found");
}
} catch {
console.error("todo Not found");
} catch (error) {
console.error(error.message);
}
}
@ -46,3 +54,5 @@ export class NotificationService {
console.log("Sending notification for Todo:", todo._id);
}
}
new NotificationService();

View file

@ -9,7 +9,7 @@ Content-Type: application/json
{
"title": "-2!!!!NEW!!!!",
"description": "Go to the gym at 8pm",
"due_date": "2023-07-09T19:00:00.891Z"
"due_date": "2023-07-13T19:00:00.891Z"
}
### update request

View file

@ -71,6 +71,6 @@ export class RabbitMQ {
calculateDelayTimeForQueue(payload: ITodo) {
const delayTime = payload.due_date.getTime() - this.currentDate.getCurrentDate().getTime();
return delayTime;
return 0;
}
}