-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8619 from ever-co/feat/dashboard-api
[Feature] Dashboard API
- Loading branch information
Showing
33 changed files
with
512 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/core/src/lib/dashboard/commands/dashboard.create.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ICommand } from '@nestjs/cqrs'; | ||
import { IDashboardCreateInput } from '@gauzy/contracts'; | ||
|
||
export class DashboardCreateCommand implements ICommand { | ||
static readonly type = '[Dashboard] Create'; | ||
|
||
constructor(public readonly input: IDashboardCreateInput) {} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/core/src/lib/dashboard/commands/dashboard.update.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ICommand } from '@nestjs/cqrs'; | ||
import { ID, IDashboardUpdateInput } from '@gauzy/contracts'; | ||
|
||
export class DashboardUpdateCommand implements ICommand { | ||
static readonly type = '[Dashboard] Update'; | ||
|
||
constructor(public readonly id: ID, public readonly input: IDashboardUpdateInput) {} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/core/src/lib/dashboard/commands/handlers/dashboard.create.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { IDashboard } from '@gauzy/contracts'; | ||
import { DashboardService } from '../../dashboard.service'; | ||
import { DashboardCreateCommand } from '../dashboard.create.command'; | ||
|
||
@CommandHandler(DashboardCreateCommand) | ||
export class DashboardCreateHandler implements ICommandHandler<DashboardCreateCommand> { | ||
constructor(private readonly dashboardService: DashboardService) {} | ||
|
||
/** | ||
* Handles the DashboardCreateCommand to create a new dashboard. | ||
* | ||
* @param command - The command containing the input data for dashboard creation. | ||
* @returns A promise that resolves to the created dashboard. | ||
*/ | ||
public async execute(command: DashboardCreateCommand): Promise<IDashboard> { | ||
const { input } = command; | ||
return this.dashboardService.create(input); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/core/src/lib/dashboard/commands/handlers/dashboard.update.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { IDashboard } from '@gauzy/contracts'; | ||
import { DashboardService } from '../../dashboard.service'; | ||
import { DashboardUpdateCommand } from '../dashboard.update.command'; | ||
|
||
@CommandHandler(DashboardUpdateCommand) | ||
export class DashboardUpdateHandler implements ICommandHandler<DashboardUpdateCommand> { | ||
constructor(private readonly dashboardService: DashboardService) {} | ||
|
||
/** | ||
* Handles the DashboardUpdateCommand to update an existing dashboard. | ||
* | ||
* @param command - The command containing the id and input data for dashboard update. | ||
* @returns A promise that resolves to the updated dashboard. | ||
*/ | ||
public async execute(command: DashboardUpdateCommand): Promise<IDashboard> { | ||
const { id, input } = command; | ||
return this.dashboardService.update(id, input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { DashboardCreateHandler } from './dashboard.create.handler'; | ||
import { DashboardUpdateHandler } from './dashboard.update.handler'; | ||
|
||
export const CommandHandlers = [DashboardCreateHandler, DashboardUpdateHandler]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './dashboard.create.command'; | ||
export * from './dashboard.update.command'; |
119 changes: 119 additions & 0 deletions
119
packages/core/src/lib/dashboard/dashboard.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { CommandBus } from '@nestjs/cqrs'; | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
HttpCode, | ||
HttpStatus, | ||
Param, | ||
Post, | ||
Put, | ||
Query, | ||
UseGuards | ||
} from '@nestjs/common'; | ||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
import { ID, IPagination, PermissionsEnum } from '@gauzy/contracts'; | ||
import { PermissionGuard, TenantPermissionGuard } from '../shared/guards'; | ||
import { Permissions } from '../shared/decorators'; | ||
import { UseValidationPipe, UUIDValidationPipe } from '../shared/pipes'; | ||
import { CrudController, PaginationParams } from '../core/crud'; | ||
import { Dashboard } from './dashboard.entity'; | ||
import { DashboardService } from './dashboard.service'; | ||
import { DashboardCreateCommand, DashboardUpdateCommand } from './commands'; | ||
import { CreateDashboardDTO, UpdateDashboardDTO } from './dto'; | ||
import { DeleteResult } from 'typeorm'; | ||
|
||
@ApiTags('Dashboard') | ||
@UseGuards(TenantPermissionGuard, PermissionGuard) | ||
@Permissions(PermissionsEnum.DASHBOARD_READ) | ||
@Controller('dashboard') | ||
export class DashboardController extends CrudController<Dashboard> { | ||
constructor(private readonly dashboardService: DashboardService, private readonly commandBus: CommandBus) { | ||
super(dashboardService); | ||
} | ||
|
||
@ApiOperation({ summary: 'Get dashboards.' }) | ||
@ApiResponse({ | ||
status: HttpStatus.OK, | ||
description: 'Found dashboards', | ||
type: Dashboard | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.NOT_FOUND, | ||
description: 'Records not found' | ||
}) | ||
@Permissions(PermissionsEnum.ALL_ORG_VIEW, PermissionsEnum.DASHBOARD_READ) | ||
@Get() | ||
async findAll(@Query() params: PaginationParams<Dashboard>): Promise<IPagination<Dashboard>> { | ||
return this.dashboardService.findAll(params); | ||
} | ||
|
||
@ApiOperation({ summary: 'Find by id.' }) | ||
@ApiResponse({ | ||
status: HttpStatus.OK, | ||
description: 'Found dashboard', | ||
type: Dashboard | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.NOT_FOUND, | ||
description: 'Record not found' | ||
}) | ||
@Permissions(PermissionsEnum.ALL_ORG_VIEW, PermissionsEnum.DASHBOARD_READ) | ||
@Get(':id') | ||
@UseValidationPipe() | ||
async findById( | ||
@Param('id', UUIDValidationPipe) id: ID, | ||
@Query() params: PaginationParams<Dashboard> | ||
): Promise<Dashboard> { | ||
return this.dashboardService.findOneByIdString(id, params); | ||
} | ||
|
||
@ApiOperation({ summary: 'Create dashboard.' }) | ||
@ApiResponse({ | ||
status: HttpStatus.CREATED, | ||
description: 'The record has been successfully created.' | ||
}) | ||
@Permissions(PermissionsEnum.ALL_ORG_EDIT, PermissionsEnum.DASHBOARD_CREATE) | ||
@Post() | ||
@UseValidationPipe({ whitelist: true }) | ||
async create(@Body() entity: CreateDashboardDTO): Promise<Dashboard> { | ||
return await this.commandBus.execute(new DashboardCreateCommand(entity)); | ||
} | ||
|
||
@ApiOperation({ summary: 'Update dashboard.' }) | ||
@ApiResponse({ | ||
status: HttpStatus.CREATED, | ||
description: 'The record has been successfully updated.' | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.NOT_FOUND, | ||
description: 'Record not found' | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.BAD_REQUEST, | ||
description: 'Invalid input, The response body may contain clues as to what went wrong' | ||
}) | ||
@HttpCode(HttpStatus.ACCEPTED) | ||
@Permissions(PermissionsEnum.ALL_ORG_EDIT, PermissionsEnum.DASHBOARD_UPDATE) | ||
@Put(':id') | ||
@UseValidationPipe({ whitelist: true }) | ||
async update(@Param('id', UUIDValidationPipe) id: ID, @Body() entity: UpdateDashboardDTO): Promise<Dashboard> { | ||
return await this.commandBus.execute(new DashboardUpdateCommand(id, entity)); | ||
} | ||
|
||
@ApiOperation({ summary: 'Delete dashboard.' }) | ||
@ApiResponse({ | ||
status: HttpStatus.OK, | ||
description: 'The record has been successfully deleted.' | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.NOT_FOUND, | ||
description: 'Record not found' | ||
}) | ||
@Permissions(PermissionsEnum.ALL_ORG_EDIT, PermissionsEnum.DASHBOARD_DELETE) | ||
@Delete(':id') | ||
async delete(@Param('id', UUIDValidationPipe) id: ID): Promise<DeleteResult> { | ||
return await this.dashboardService.delete(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { CqrsModule } from '@nestjs/cqrs'; | ||
import { MikroOrmModule } from '@mikro-orm/nestjs'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Module } from '@nestjs/common'; | ||
import { RolePermissionModule } from '../role-permission/role-permission.module'; | ||
import { CommandHandlers } from './commands/handlers'; | ||
import { Dashboard } from './dashboard.entity'; | ||
import { DashboardService } from './dashboard.service'; | ||
import { DashboardController } from './dashboard.controller'; | ||
import { TypeOrmDashboardRepository } from './repository/type-orm-dashboard.repository'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forFeature([Dashboard]), | ||
MikroOrmModule.forFeature([Dashboard]), | ||
RolePermissionModule, | ||
CqrsModule | ||
], | ||
controllers: [], | ||
providers: [], | ||
exports: [] | ||
controllers: [DashboardController], | ||
providers: [DashboardService, TypeOrmDashboardRepository, ...CommandHandlers], | ||
exports: [TypeOrmModule, DashboardService, TypeOrmDashboardRepository] | ||
}) | ||
export class DashboardModule {} |
Oops, something went wrong.