Files
twenty_crm/server/src/workspace/workspace-manager/utils/sync-metadata.util.ts
Weiko 6d4ad6ec18 Sync standard object metadata (#2807)
* Sync standard object metadata

* remove debug logging

* remove unused func

* fix comments

* fix empty objectsToDelete list
2023-12-05 14:10:50 +01:00

42 lines
1.4 KiB
TypeScript

import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
/**
* This utility function filters out properties from an object based on a list of properties to ignore.
* It returns a new object with only the properties that are not in the ignore list.
*
* @param obj - The object to filter.
* @param propertiesToIgnore - An array of property names to ignore.
* @returns A new object with filtered properties.
*/
export const filterIgnoredProperties = (
obj: any,
propertiesToIgnore: string[],
) => {
return Object.fromEntries(
Object.entries(obj).filter(([key]) => !propertiesToIgnore.includes(key)),
);
};
/**
* This utility function converts an array of ObjectMetadataEntity objects into a map,
* where the keys are the nameSingular properties of the objects.
* Each object in the map contains the original object metadata and its fields as a nested map.
*
* @param arr - The array of ObjectMetadataEntity objects to convert.
* @returns A map of object metadata, with nameSingular as the key and the object as the value.
*/
export const mapObjectMetadataByUniqueIdentifier = (
arr: ObjectMetadataEntity[],
) => {
return arr.reduce((acc, curr) => {
acc[curr.nameSingular] = {
...curr,
fields: curr.fields.reduce((acc, curr) => {
acc[curr.name] = curr;
return acc;
}, {}),
};
return acc;
}, {});
};