Spaces:
Build error
Build error
twenty / packages /twenty-server /src /engine /metadata-modules /page-layout-widget /controllers /page-layout-widget.controller.ts
| import { | |
| Body, | |
| Controller, | |
| Delete, | |
| Get, | |
| Param, | |
| Patch, | |
| Post, | |
| Query, | |
| UseFilters, | |
| UseGuards, | |
| } from '@nestjs/common'; | |
| import { isDefined } from 'class-validator'; | |
| import { PermissionFlagType } from 'twenty-shared/constants'; | |
| import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity'; | |
| import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator'; | |
| import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard'; | |
| import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard'; | |
| import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard'; | |
| import { FlatEntityMapsRestApiExceptionFilter } from 'src/engine/metadata-modules/flat-entity/filters/flat-entity-maps-rest-api-exception.filter'; | |
| import { CreatePageLayoutWidgetInput } from 'src/engine/metadata-modules/page-layout-widget/dtos/inputs/create-page-layout-widget.input'; | |
| import { UpdatePageLayoutWidgetInput } from 'src/engine/metadata-modules/page-layout-widget/dtos/inputs/update-page-layout-widget.input'; | |
| import { type PageLayoutWidgetDTO } from 'src/engine/metadata-modules/page-layout-widget/dtos/page-layout-widget.dto'; | |
| import { | |
| generatePageLayoutWidgetExceptionMessage, | |
| PageLayoutWidgetException, | |
| PageLayoutWidgetExceptionCode, | |
| PageLayoutWidgetExceptionMessageKey, | |
| } from 'src/engine/metadata-modules/page-layout-widget/exceptions/page-layout-widget.exception'; | |
| import { PageLayoutWidgetRestApiExceptionFilter } from 'src/engine/metadata-modules/page-layout-widget/filters/page-layout-widget-rest-api-exception.filter'; | |
| import { PageLayoutWidgetService } from 'src/engine/metadata-modules/page-layout-widget/services/page-layout-widget.service'; | |
| import { PermissionsRestApiExceptionFilter } from 'src/engine/metadata-modules/permissions/utils/permissions-rest-api-exception.filter'; | |
| import { WorkspaceMigrationRunnerRestApiExceptionFilter } from 'src/engine/workspace-manager/workspace-migration/filters/workspace-migration-runner-rest-api-exception.filter'; | |
| ('rest/metadata/pageLayoutWidgets') | |
| (WorkspaceAuthGuard) | |
| ( | |
| PermissionsRestApiExceptionFilter, | |
| PageLayoutWidgetRestApiExceptionFilter, | |
| FlatEntityMapsRestApiExceptionFilter, | |
| WorkspaceMigrationRunnerRestApiExceptionFilter, | |
| ) | |
| export class PageLayoutWidgetController { | |
| constructor( | |
| private readonly pageLayoutWidgetService: PageLayoutWidgetService, | |
| ) {} | |
| () | |
| (NoPermissionGuard) | |
| async findMany( | |
| () workspace: WorkspaceEntity, | |
| ('pageLayoutTabId') pageLayoutTabId: string, | |
| ): Promise<PageLayoutWidgetDTO[]> { | |
| if (!isDefined(pageLayoutTabId)) { | |
| throw new PageLayoutWidgetException( | |
| generatePageLayoutWidgetExceptionMessage( | |
| PageLayoutWidgetExceptionMessageKey.PAGE_LAYOUT_TAB_ID_REQUIRED, | |
| ), | |
| PageLayoutWidgetExceptionCode.INVALID_PAGE_LAYOUT_WIDGET_DATA, | |
| ); | |
| } | |
| return this.pageLayoutWidgetService.findByPageLayoutTabId({ | |
| workspaceId: workspace.id, | |
| pageLayoutTabId, | |
| }); | |
| } | |
| (':id') | |
| (NoPermissionGuard) | |
| async findOne( | |
| ('id') id: string, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<PageLayoutWidgetDTO | null> { | |
| return this.pageLayoutWidgetService.findByIdOrThrow({ | |
| id, | |
| workspaceId: workspace.id, | |
| }); | |
| } | |
| () | |
| (SettingsPermissionGuard(PermissionFlagType.LAYOUTS)) | |
| async create( | |
| () input: CreatePageLayoutWidgetInput, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<PageLayoutWidgetDTO> { | |
| return this.pageLayoutWidgetService.create({ | |
| input, | |
| workspaceId: workspace.id, | |
| }); | |
| } | |
| (':id') | |
| (SettingsPermissionGuard(PermissionFlagType.LAYOUTS)) | |
| async update( | |
| ('id') id: string, | |
| () input: UpdatePageLayoutWidgetInput, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<PageLayoutWidgetDTO> { | |
| return this.pageLayoutWidgetService.update({ | |
| id, | |
| workspaceId: workspace.id, | |
| updateData: input, | |
| }); | |
| } | |
| (':id') | |
| (SettingsPermissionGuard(PermissionFlagType.LAYOUTS)) | |
| async destroy( | |
| ('id') id: string, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<boolean> { | |
| return this.pageLayoutWidgetService.destroy({ | |
| id, | |
| workspaceId: workspace.id, | |
| }); | |
| } | |
| } | |