Skip to content

Commit

Permalink
Automatically update dashboard.content_id
Browse files Browse the repository at this point in the history
Update dashboard.content_id when null upon creation of dashboard content
  • Loading branch information
miguel-lansdorf committed Oct 31, 2023
1 parent d4ec867 commit c863a50
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 c863a50

Please sign in to comment.