1+ import { MailerInterface } from "./mailerInterface" ;
2+ import { TemplatingEngineInterface } from "./TemplatingEngineInterface" ;
3+ import { TranslatorInterface } from "./translatorInterface" ;
4+
5+ export class User {
6+ public getConfirmCode ( ) : string {
7+ return Math . floor ( Math . random ( ) * 10 ) . toString ( )
8+ }
9+
10+ public getEmailAddress ( ) : string {
11+ return "Mahdi@gmail.com"
12+ }
13+ }
14+ export class Message {
15+ private subject :string ;
16+ private body :string ;
17+ private emailAddress :string ;
18+
19+ constructor (
20+ subject ,
21+ body ,
22+ emailAddress
23+ ) {
24+ this . subject = subject ;
25+ this . body = body ;
26+ this . emailAddress = emailAddress ;
27+ }
28+ }
29+
30+ class ConfirmationMailMailer {
31+ private templating : TemplatingEngineInterface ;
32+ private translator : TranslatorInterface ;
33+ private mailer : MailerInterface ;
34+
35+ constructor (
36+ templating : TemplatingEngineInterface ,
37+ translator : TranslatorInterface ,
38+ mailer : MailerInterface
39+ ) {
40+ this . templating = templating ;
41+ this . translator = translator ;
42+ this . mailer = mailer ;
43+ }
44+
45+ private createMesssageFor ( user : User ) : Message {
46+ const subject = this . translator . translate ( "Please Confirm Your Email Address" ) ;
47+ const body = this . templating . render ( "mail.confirm" , [
48+ "Hello Sir." ,
49+ "Thanks For Your Signup !" ,
50+ `Your Code is ${ user . getConfirmCode ( ) } ` ,
51+ "Regards♥" ] ) ;
52+ return new Message ( subject , body , user . getEmailAddress ( ) )
53+ }
54+
55+ public sendTo ( user : User ) {
56+ const message = this . createMesssageFor ( user ) ;
57+ this . sendMessage ( message ) ;
58+ }
59+
60+ public sendMessage ( message : Message ) {
61+ this . mailer . send ( message )
62+ }
63+
64+ }
0 commit comments