myfreight-assessment/src/tracking/notifications/console.notifier.ts

36 lines
926 B
TypeScript

import { NotifierAbstract } from '@/tracking/notifications/notifier.abstract';
import { INotifier } from '@/tracking/notifications/notifier.types';
export class ConsoleNotifier extends NotifierAbstract implements INotifier {
async send(): Promise<boolean> {
const messages = this.generateMessages();
if (!messages.length) {
console.log('Dont send email');
return false;
}
console.log(
`Send email with the following messages: ${messages.join('\n')}`,
);
return true;
}
private generateMessages(): string[] {
const messages: string[] = [];
if (this.isDelayed) {
messages.push('Your shipment has been delayed.');
}
if (this.daysToArrival <= 0) {
messages.push('Your shipment has arrived');
}
if (this.daysToArrival > 0 && this.daysToArrival <= 1) {
messages.push('Your shipment will arrive soon');
}
return messages;
}
}