Migrate page layout services (#16443)

Last step of the page layout migration:
- Migrate services
- Write integration tests
This commit is contained in:
Raphaël Bosi
2025-12-10 14:49:44 +01:00
committed by GitHub
parent 1839f8e946
commit f48adb5f07
157 changed files with 6099 additions and 7586 deletions
@@ -0,0 +1,51 @@
import { t } from '@lingui/core/macro';
import {
extractAndSanitizeObjectStringFields,
isDefined,
} from 'twenty-shared/utils';
import { type FlatPageLayoutWidgetMaps } from 'src/engine/metadata-modules/flat-page-layout-widget/types/flat-page-layout-widget-maps.type';
import { type FlatPageLayoutWidget } from 'src/engine/metadata-modules/flat-page-layout-widget/types/flat-page-layout-widget.type';
import {
PageLayoutWidgetException,
PageLayoutWidgetExceptionCode,
} from 'src/engine/metadata-modules/page-layout/exceptions/page-layout-widget.exception';
export type RestorePageLayoutWidgetInput = {
id: string;
};
export const fromRestorePageLayoutWidgetInputToFlatPageLayoutWidgetOrThrow = ({
restorePageLayoutWidgetInput,
flatPageLayoutWidgetMaps,
}: {
restorePageLayoutWidgetInput: RestorePageLayoutWidgetInput;
flatPageLayoutWidgetMaps: FlatPageLayoutWidgetMaps;
}): FlatPageLayoutWidget => {
const { id: pageLayoutWidgetId } = extractAndSanitizeObjectStringFields(
restorePageLayoutWidgetInput,
['id'],
);
const existingFlatPageLayoutWidgetToRestore =
flatPageLayoutWidgetMaps.byId[pageLayoutWidgetId];
if (!isDefined(existingFlatPageLayoutWidgetToRestore)) {
throw new PageLayoutWidgetException(
t`Page layout widget to restore not found`,
PageLayoutWidgetExceptionCode.PAGE_LAYOUT_WIDGET_NOT_FOUND,
);
}
if (!isDefined(existingFlatPageLayoutWidgetToRestore.deletedAt)) {
throw new PageLayoutWidgetException(
t`Page layout widget is not deleted and cannot be restored`,
PageLayoutWidgetExceptionCode.INVALID_PAGE_LAYOUT_WIDGET_DATA,
);
}
return {
...existingFlatPageLayoutWidgetToRestore,
deletedAt: null,
};
};