Skip to content

Commit

Permalink
Merge pull request #1265 from merico-dev/1264-creating-dashboard-cont…
Browse files Browse the repository at this point in the history
…ent-should-automatically-update-dashboardcontent_id-if-null

Automatically update dashboard.content_id
  • Loading branch information
miguel-lansdorf authored Oct 31, 2023
2 parents d4ec867 + c863a50 commit 9a350db
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/src/services/dashboard_content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class DashboardContentService {

async create(dashboard_id: string, name: string, content: Content, locale: string): Promise<DashboardContent> {
const dashboardContentRepo = dashboardDataSource.getRepository(DashboardContent);
const dashboardRepo = dashboardDataSource.getRepository(Dashboard);
if (await dashboardContentRepo.exist({ where: { dashboard_id, name } })) {
throw new ApiError(BAD_REQUEST, { message: translate('DASHBOARD_CONTENT_NAME_ALREADY_EXISTS', locale) });
}
Expand All @@ -133,7 +134,13 @@ export class DashboardContentService {
if (!(await migrateOneDashboardContent(dashboardContent))) {
throw new ApiError(BAD_REQUEST, { message: translate('DASHBOARD_CONTENT_MIGRATION_FAILED', locale) });
}
return dashboardContentRepo.save(dashboardContent);
const result = await dashboardContentRepo.save(dashboardContent);
const dashboard = await dashboardRepo.findOneByOrFail({ id: dashboard_id });
if (!dashboard.content_id) {
dashboard.content_id = result.id;
await dashboardRepo.save(dashboard);
}
return result;
}

async get(id: string): Promise<DashboardContent> {
Expand Down

0 comments on commit 9a350db

Please sign in to comment.