chore: Do not try to encrypt or decrypt if data field is empty

This commit is contained in:
Faruk AYDIN
2021-11-28 22:43:47 +01:00
committed by Ömer Faruk Aydın
parent f949eca3c4
commit 3e4768c106

View File

@@ -39,13 +39,19 @@ class Connection extends Base {
})
encryptData() {
if(!this.eligibleForEncryption()) return;
this.data = AES.encrypt(JSON.stringify(this.data), appConfig.encryptionKey).toString();
}
decryptData() {
if(!this.eligibleForEncryption()) return;
this.data = JSON.parse(AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8));
}
eligibleForEncryption() {
return this.data ? true : false
}
// TODO: Make another abstraction like beforeSave instead of using
// beforeInsert and beforeUpdate separately for the same operation.
async $beforeInsert(queryContext: QueryContext) {