Skip to content

Commit

Permalink
fix: error message for find operators
Browse files Browse the repository at this point in the history
  • Loading branch information
theo committed Dec 7, 2021
1 parent 033ce85 commit 21f88fb
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,8 @@ export class JSONEncryptionTransformer implements ValueTransformer {
if (!value) {
return;
}
// Support FindOperator.
// Just support "Equal", "In", "Not", and "IsNull".
// Other operators aren't work correctly, because values are encrypted on the db.
if (value.type === `in`) {
return In((value.value as string[]).map(s =>
encryptData(
Buffer.from(s, 'utf-8'),
this.options
).toString('base64')
));
} else if (value.type === 'equal') {
return Equal(encryptData(
Buffer.from(value.value as string, 'utf-8'),
this.options
).toString('base64'));
} else if (value.type === 'not') {
return Not(
this.to(value.child ?? value.value)
);
} else if (value.type === 'isNull') {
return value
} else {
throw new Error('Only "Equal","In", "Not", and "IsNull" are supported for FindOperator');
}

// FindOperators are not supported.
throw new Error('Filter operators are not supported for JSON encrypted fields');
}
}

0 comments on commit 21f88fb

Please sign in to comment.