https://github.com/user-attachments/assets/aac81e79-7f2f-4a34-bf68-c76061086821 --------- Co-authored-by: Weiko <corentin@twenty.com>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
type EntityWithApplicationIdentifierAndOverrides = {
|
|
applicationUniversalIdentifier: string;
|
|
isActive: boolean;
|
|
overrides: unknown;
|
|
};
|
|
|
|
export const splitEntitiesByResetStrategy = <
|
|
T extends EntityWithApplicationIdentifierAndOverrides,
|
|
>({
|
|
entities,
|
|
workspaceCustomApplicationUniversalIdentifier,
|
|
now,
|
|
}: {
|
|
entities: T[];
|
|
workspaceCustomApplicationUniversalIdentifier: string;
|
|
now: string;
|
|
}): {
|
|
toHardDelete: T[];
|
|
toReset: (T & { isActive: true; overrides: null; updatedAt: string })[];
|
|
} => {
|
|
const toHardDelete: T[] = [];
|
|
const toReset: (T & {
|
|
isActive: true;
|
|
overrides: null;
|
|
updatedAt: string;
|
|
})[] = [];
|
|
|
|
for (const entity of entities) {
|
|
if (
|
|
entity.applicationUniversalIdentifier ===
|
|
workspaceCustomApplicationUniversalIdentifier
|
|
) {
|
|
toHardDelete.push(entity);
|
|
} else {
|
|
toReset.push({
|
|
...entity,
|
|
isActive: true as const,
|
|
overrides: null,
|
|
...('universalOverrides' in entity ? { universalOverrides: null } : {}),
|
|
updatedAt: now,
|
|
});
|
|
}
|
|
}
|
|
|
|
return { toHardDelete, toReset };
|
|
};
|