Добавлен ендпоинт получения списка публичных дашбордов
This commit is contained in:
parent
0b82ca564a
commit
2687062906
3 changed files with 35 additions and 0 deletions
18
libs/event-emitter/src/dashboards/dashboards.controller.ts
Normal file
18
libs/event-emitter/src/dashboards/dashboards.controller.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Controller, Get } from '@nestjs/common';
|
||||
import { DashboardsService } from './dashboards.service';
|
||||
import { BadRequestErrorHandler, getOrAppErrorOrThrow } from '../utils/result';
|
||||
import { UNLIMITED } from '../consts/consts';
|
||||
|
||||
@Controller('api/dashboards')
|
||||
export class DashboardsController {
|
||||
constructor(private dashboardsService: DashboardsService) {}
|
||||
|
||||
@Get()
|
||||
async list(): Promise<any> {
|
||||
const res = await getOrAppErrorOrThrow(
|
||||
() => this.dashboardsService.publicList(UNLIMITED),
|
||||
BadRequestErrorHandler,
|
||||
);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -71,4 +71,19 @@ export class DashboardsService {
|
|||
await ds.insert(newValue);
|
||||
return;
|
||||
}
|
||||
|
||||
async publicList(limit: number): Promise<{ id: string; title: string }[]> {
|
||||
const ds = await this.db.getDatasource();
|
||||
const data = await ds.find({
|
||||
selector: {
|
||||
'data.title': {
|
||||
$exists: true,
|
||||
},
|
||||
},
|
||||
fields: ['id', 'data.title'],
|
||||
limit: limit,
|
||||
});
|
||||
if (!data.docs) throw createAppError('DASHBOARDS_NOT_FOUND');
|
||||
return data.docs.map((d) => ({ id: d.id, title: d.data.title }));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import { ListIssuesByUsersWidgetDataLoaderService } from './dashboards/widget-da
|
|||
import { ListIssuesByUsersLikeJiraWidgetDataLoaderService } from './dashboards/widget-data-loader/list-issues-by-users-like-jira.widget-data-loader.service';
|
||||
import { ListIssuesByFieldsWidgetDataLoaderService } from './dashboards/widget-data-loader/list-issues-by-fields.widget-data-loader.service';
|
||||
import { WidgetsCollectionService } from './dashboards/widgets-collection.service';
|
||||
import { DashboardsController } from './dashboards/dashboards.controller';
|
||||
|
||||
@Module({})
|
||||
export class EventEmitterModule implements OnModuleInit {
|
||||
|
|
@ -148,6 +149,7 @@ export class EventEmitterModule implements OnModuleInit {
|
|||
IssuesController,
|
||||
CalendarController,
|
||||
DashboardController,
|
||||
DashboardsController,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue