srn Helper method correction

This commit is contained in:
sumit_chaturvedi
2025-05-21 21:56:32 +05:30
parent 0206674fc9
commit c1380e397c
2 changed files with 27 additions and 20 deletions
+27
View File
@@ -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;
}
-20
View File
@@ -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;
}