Files
twenty/packages/twenty-server/src/engine/metadata-modules/flat-view-group/utils/from-create-view-group-input-to-flat-view-group-to-create.util.ts
T
Weiko cceeb6ed4d Add applicationId to syncableEntity and fix syncApp deletion (#15170)
## Context
- All flatEntity should extend SyncableEntity
- SyncableEntity should now have applicationId and application relation
- Fix syncApp deletion, should now properly use migration v2 to delete
syncable entities
2025-10-17 17:23:00 +00:00

39 lines
1.3 KiB
TypeScript

import { trimAndRemoveDuplicatedWhitespacesFromObjectStringProperties } from 'twenty-shared/utils';
import { v4 } from 'uuid';
import { type FlatViewGroup } from 'src/engine/metadata-modules/flat-view-group/types/flat-view-group.type';
import { type CreateViewGroupInput } from 'src/engine/metadata-modules/view-group/dtos/inputs/create-view-group.input';
export const fromCreateViewGroupInputToFlatViewGroupToCreate = ({
createViewGroupInput: rawCreateViewGroupInput,
workspaceId,
}: {
createViewGroupInput: CreateViewGroupInput;
workspaceId: string;
}): FlatViewGroup => {
const { fieldMetadataId, viewId, ...createViewGroupInput } =
trimAndRemoveDuplicatedWhitespacesFromObjectStringProperties(
rawCreateViewGroupInput,
['fieldMetadataId', 'fieldValue', 'id', 'viewId'],
);
const createdAt = new Date();
const viewGroupId = createViewGroupInput.id ?? v4();
return {
id: viewGroupId,
fieldMetadataId,
viewId,
workspaceId,
createdAt: createdAt,
updatedAt: createdAt,
deletedAt: null,
universalIdentifier:
createViewGroupInput.universalIdentifier ?? viewGroupId,
isVisible: createViewGroupInput.isVisible ?? true,
fieldValue: createViewGroupInput.fieldValue,
position: createViewGroupInput.position ?? 0,
applicationId: createViewGroupInput.applicationId ?? null,
};
};