refactor: Pass app data within the constructor of an app

This commit is contained in:
Faruk AYDIN
2022-02-27 18:22:17 +03:00
committed by Ali BARIN
parent 003213d223
commit c864a1062d
24 changed files with 216 additions and 174 deletions

View File

@@ -1,12 +1,11 @@
import nodemailer from 'nodemailer';
import App from '../../models/app';
export default class Authentication {
client: any
connectionData: any
appData: any
client: any;
connectionData: any;
appData: any;
constructor(connectionData: any) {
constructor(appData: any, connectionData: any) {
this.client = nodemailer.createTransport({
host: connectionData.host,
port: connectionData.port,
@@ -18,23 +17,23 @@ export default class Authentication {
});
this.connectionData = connectionData;
this.appData = App.findOneByKey('smtp');
this.appData = appData;
}
async verifyCredentials() {
await this.client.verify()
await this.client.verify();
return {
screenName: this.connectionData.username
}
screenName: this.connectionData.username,
};
}
async isStillVerified() {
try {
await this.client.verify()
await this.client.verify();
return true;
} catch(error) {
return false
} catch (error) {
return false;
}
}
}

View File

@@ -1,9 +1,9 @@
import Authentication from './authentication';
export default class SMTP {
authenticationClient: any
authenticationClient: any;
constructor(connectionData: any) {
this.authenticationClient = new Authentication(connectionData);
constructor(appData: any, connectionData: any) {
this.authenticationClient = new Authentication(appData, connectionData);
}
}