Skip to content
Snippets Groups Projects
Commit a8a12a4d authored by roshan's avatar roshan
Browse files

where encryption logic added, redis ip changed to niveus ip

parent ea16507a
Branches
No related tags found
No related merge requests found
......@@ -91,20 +91,59 @@ function encryptFields(model: string, data: any): any {
}
function encryptWhere(model: string, where: any): any {
if (!where || typeof where !== 'object') return where;
const fields = getEncryptedFields()[model];
if (!fields || !where) return where;
const encryptedWhere: any = {};
for (const field of fields) {
if (where[field]) {
where[field] = encryptToBytes(where[field]);
for (const key of Object.keys(where)) {
const value = where[key];
if (Array.isArray(value)) {
// Handles AND / OR / NOT as arrays
encryptedWhere[key] = value.map(v => encryptWhere(model, v));
} else if (typeof value === 'object' && value !== null) {
if (fields?.includes(key)) {
// Handle field-level operators like `equals`, `contains`, etc.
encryptedWhere[key] = encryptFieldOperators(value);
} else if (['some', 'every', 'none'].some(op => Object.keys(value).includes(op))) {
// Handle relation filters for lists
encryptedWhere[key] = {};
for (const relOp of ['some', 'every', 'none']) {
if (value[relOp]) {
encryptedWhere[key][relOp] = encryptWhere(key, value[relOp]);
}
}
} else {
// Assume it's a nested relation
encryptedWhere[key] = encryptWhere(key, value);
}
} else {
// Primitive field value
if (fields?.includes(key)) {
encryptedWhere[key] = encryptToBytes(value);
} else {
encryptedWhere[key] = value;
}
}
}
return where;
return encryptedWhere;
}
function encryptFieldOperators(value: any): any {
if (!value || typeof value !== 'object') return encryptToBytes(value);
const encrypted: any = {};
for (const op in value) {
encrypted[op] = encryptToBytes(value[op]);
}
return encrypted;
}
function decryptFields(model: string, record: any): any {
const fields = getEncryptedFields()[model];
if (!record || typeof record !== 'object') return record;
const fields = getEncryptedFields()[model];
// Decrypt current model's fields
if (fields) {
......
......@@ -4,7 +4,7 @@ import { Logger } from './logger.util';
export class RedisWrapper {
private static eventsRegistered = false;
private redisURL: string = process.env.REDIS_URL || "redis://localhost:6379";
private redisURL: string = process.env.REDIS_URL || "redis://10.8.0.2:6379";
private client: Redis = new Redis(this.redisURL);
private subscriber: Redis = new Redis(this.redisURL);
private logger = new Logger();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment