diff --git a/backend/tasks.js b/backend/tasks.js index 2014da3..ba6379c 100644 --- a/backend/tasks.js +++ b/backend/tasks.js @@ -42,9 +42,9 @@ function scheduleJob(task_key, schedule) { if (schedule['type'] === 'timestamp') { converted_schedule = new Date(schedule['data']['timestamp']); } else if (schedule['type'] === 'recurring') { - const dayOfWeek = schedule['data']['dayOfWeek'] ? schedule['data']['dayOfWeek'] : null; - const hour = schedule['data']['hour'] ? schedule['data']['hour'] : null; - const minute = schedule['data']['minute'] ? schedule['data']['minute'] : null; + const dayOfWeek = schedule['data']['dayOfWeek'] != null ? schedule['data']['dayOfWeek'] : null; + const hour = schedule['data']['hour'] != null ? schedule['data']['hour'] : null; + const minute = schedule['data']['minute'] != null ? schedule['data']['minute'] : null; converted_schedule = new scheduler.RecurrenceRule(null, null, null, dayOfWeek, hour, minute); } else { logger.error(`Failed to schedule job '${task_key}' as the type '${schedule['type']}' is invalid.`) diff --git a/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts b/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts index ef61cf4..2d31782 100644 --- a/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts +++ b/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts @@ -1,6 +1,6 @@ import { Component, Inject, OnInit } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { Schedule } from 'api-types'; +import { Schedule, Task } from 'api-types'; import { PostsService } from 'app/posts.services'; @Component({ @@ -18,7 +18,7 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { date = null; today = new Date(); - constructor(@Inject(MAT_DIALOG_DATA) public data: any, private dialogRef: MatDialogRef, private postsService: PostsService) { + constructor(@Inject(MAT_DIALOG_DATA) public data: {task: Task}, private dialogRef: MatDialogRef, private postsService: PostsService) { this.processTask(this.data.task); this.postsService.getTask(this.data.task.key).subscribe(res => { this.processTask(res['task']); @@ -28,7 +28,7 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { ngOnInit(): void { } - processTask(task) { + processTask(task: Task): void { if (!task['schedule']) { this.enabled = false; return; @@ -39,7 +39,11 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { this.recurring = schedule['type'] === Schedule.type.RECURRING; if (this.recurring) { - this.time = `${schedule['data']['hour']}:${schedule['data']['minute']}`; + const hour = schedule['data']['hour']; + const minute = schedule['data']['minute']; + + // add padding 0s if necessary to hours and minutes + this.time = (hour < 10 ? '0' : '') + hour + ':' + (minute < 10 ? '0' : '') + minute; if (schedule['data']['dayOfWeek']) { this.days_of_week = schedule['data']['dayOfWeek']; @@ -75,7 +79,6 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { } } else { this.date.setHours(hours, minutes); - console.log(this.date); schedule['data'] = {timestamp: this.date.getTime()}; } this.dialogRef.close(schedule);