fix: Adjust info.json files to work with formattedData field
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
6a8ec97c31
commit
e73f33f3db
@@ -19,7 +19,7 @@ class Connection extends Base {
|
||||
|
||||
static jsonSchema = {
|
||||
type: 'object',
|
||||
required: ['key', 'data'],
|
||||
required: ['key'],
|
||||
|
||||
properties: {
|
||||
id: { type: 'string', format: 'uuid' },
|
||||
@@ -44,14 +44,18 @@ class Connection extends Base {
|
||||
|
||||
encryptData(): void {
|
||||
if (!this.eligibleForEncryption()) return;
|
||||
|
||||
this.data = AES.encrypt(
|
||||
JSON.stringify(this.formattedData),
|
||||
appConfig.encryptionKey
|
||||
).toString();
|
||||
|
||||
delete this['formattedData'];
|
||||
}
|
||||
|
||||
decryptData(): void {
|
||||
if (!this.eligibleForEncryption()) return;
|
||||
if (!this.eligibleForDecryption()) return;
|
||||
|
||||
this.formattedData = JSON.parse(
|
||||
AES.decrypt(this.data, appConfig.encryptionKey).toString(enc.Utf8)
|
||||
);
|
||||
@@ -61,6 +65,10 @@ class Connection extends Base {
|
||||
return this.formattedData ? true : false;
|
||||
}
|
||||
|
||||
eligibleForDecryption(): boolean {
|
||||
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): Promise<void> {
|
||||
|
Reference in New Issue
Block a user