chore: Do not try to encrypt or decrypt if data field is empty
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
f949eca3c4
commit
3e4768c106
@@ -39,13 +39,19 @@ class Connection extends Base {
|
|||||||
})
|
})
|
||||||
|
|
||||||
encryptData() {
|
encryptData() {
|
||||||
|
if(!this.eligibleForEncryption()) return;
|
||||||
this.data = AES.encrypt(JSON.stringify(this.data), appConfig.encryptionKey).toString();
|
this.data = AES.encrypt(JSON.stringify(this.data), appConfig.encryptionKey).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
decryptData() {
|
decryptData() {
|
||||||
|
if(!this.eligibleForEncryption()) return;
|
||||||
this.data = JSON.parse(AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8));
|
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
|
// TODO: Make another abstraction like beforeSave instead of using
|
||||||
// beforeInsert and beforeUpdate separately for the same operation.
|
// beforeInsert and beforeUpdate separately for the same operation.
|
||||||
async $beforeInsert(queryContext: QueryContext) {
|
async $beforeInsert(queryContext: QueryContext) {
|
||||||
|
Reference in New Issue
Block a user