mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
srn Helper method correction
This commit is contained in:
@@ -44,3 +44,30 @@ export const extractSortAndKey = (searchParams: Record<string, unknown>) => {
|
||||
|
||||
return { searchParamsKey, rawSort, encodedSort };
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces a specific field name inside a filter-style key of an object.
|
||||
* @param obj - The input object with filter-style keys (e.g., { 'filter[inserted_at]': '2025-05-21' }).
|
||||
* @param oldField - The field name to be replaced (e.g., 'inserted_at').
|
||||
* @param newField - The field name to replace with (e.g., 'updated_at').
|
||||
* @returns A new object with the updated filter key if a match is found.
|
||||
*/
|
||||
export function replaceFilterFieldKey(
|
||||
obj: Record<string, string>,
|
||||
oldField: string,
|
||||
newField: string,
|
||||
): Record<string, string> {
|
||||
const fieldObj: Record<string, string> = {};
|
||||
|
||||
for (const key in obj) {
|
||||
const match = key.match(/^filter\[(.+)\]$/);
|
||||
if (match && match[1] === oldField) {
|
||||
const newKey = `filter[${newField}]`;
|
||||
fieldObj[newKey] = obj[key];
|
||||
} else {
|
||||
fieldObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
return fieldObj;
|
||||
}
|
||||
|
||||
@@ -269,23 +269,3 @@ export const permissionFormFields: PermissionInfo[] = [
|
||||
description: "Provides access to billing settings and invoices",
|
||||
},
|
||||
];
|
||||
|
||||
export function replaceFilterFieldKey(
|
||||
obj: Record<string, string>,
|
||||
oldField: string,
|
||||
newField: string,
|
||||
): Record<string, string> {
|
||||
const fieldObj: Record<string, string> = {};
|
||||
|
||||
for (const key in obj) {
|
||||
const match = key.match(/^filter\[(.+)\]$/);
|
||||
if (match && match[1] === oldField) {
|
||||
const newKey = `filter[${newField}]`;
|
||||
fieldObj[newKey] = obj[key];
|
||||
} else {
|
||||
fieldObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
return fieldObj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user