-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WAITP-1255: Tupaia web server report and dashboard routes (#4602)
* WAITP-1255 Add web config to api client * WAITP-1255 Add user and report route to tupaia-web-server * WAITP-1255 Update SessionSwitchingAuthHandler to use util functions * WAITP-1255 Add fetchReport to ReportApi * WAITP-1255 Add temporary logout route * WAITP-1255 Allow no session in attach function * WAITP-1255 Update user route default to match current web config server behaviour * WAITP-1255 Add dashboard route to tupaia-web-server * WAITP-1255 Add mock web config api * WAITP-1255 Remove unnecessary SessionCookie redefinition * WAITP-1255 PR Fixups * WAITP-1255 Add mock export * WAITP-1255 Only discard 401s from attachSession * WAITP-1255 Do it the recommended way instead
- Loading branch information
Showing
21 changed files
with
226 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { QueryParameters } from '../types'; | ||
import { BaseApi } from './BaseApi'; | ||
import { PublicInterface } from './types'; | ||
|
||
export class WebConfigApi extends BaseApi { | ||
public async fetchReport(reportCode: string, query?: QueryParameters | null) { | ||
return this.connection.get(`report/${reportCode}`, query); | ||
} | ||
} | ||
|
||
export interface WebConfigApiInterface extends PublicInterface<WebConfigApi> {}; |
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
12 changes: 12 additions & 0 deletions
12
packages/api-client/src/connections/mocks/MockWebConfigApi.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,12 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { WebConfigApiInterface } from '..'; | ||
|
||
export class MockWebConfigApi implements WebConfigApiInterface { | ||
public fetchReport(): Promise<any> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { Request } from 'express'; | ||
import { Route } from '@tupaia/server-boilerplate'; | ||
|
||
export type DashboardsRequest = Request< | ||
any, | ||
any, | ||
any, | ||
any | ||
>; | ||
|
||
export class DashboardsRoute extends Route<DashboardsRequest> { | ||
public async buildResponse() { | ||
const { query, ctx } = this.req; | ||
const { organisationUnitCode, projectCode } = query; | ||
|
||
const project = (await ctx.services.central.fetchResources('projects', { filter: { code: projectCode }, columns: JSON.stringify(['entity_id', 'entity_hierarchy.name']) }))[0]; | ||
const baseEntity = await ctx.services.entity.getEntity(project['entity_hierarchy.name'], organisationUnitCode); | ||
// TODO: Add a better getAncestors function to the EntityApi | ||
const entities = await ctx.services.entity.getRelationshipsOfEntity(project['entity_hierarchy.name'], project.entity_id, 'descendant', {}, {} , { filter: { type: baseEntity.type } }); | ||
const dashboards = await ctx.services.central.fetchResources('dashboards', { filter: { root_entity_code: entities.ancestors }}); | ||
return Promise.all(dashboards.map(async (dash: any) => ({ | ||
...dash, | ||
items: await ctx.services.central.fetchResources(`dashboards/${dash.id}/dashboardRelations`) | ||
}))); | ||
} | ||
} |
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,30 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
* | ||
*/ | ||
|
||
import { Request } from 'express'; | ||
import { Route } from '@tupaia/server-boilerplate'; | ||
|
||
export type ReportRequest = Request< | ||
{ reportCode: string }, | ||
any, | ||
any, | ||
any | ||
>; | ||
|
||
export class ReportRoute extends Route<ReportRequest> { | ||
public async buildResponse() { | ||
const { query, ctx } = this.req; | ||
const { reportCode } = this.req.params; | ||
const { legacy } = query; | ||
|
||
// Legacy data builders are handled through the web config server still | ||
if (legacy === 'true') { | ||
return ctx.services.webConfig.fetchReport(reportCode, query); | ||
} | ||
|
||
return ctx.services.report.fetchReport(reportCode, query); | ||
} | ||
} |
Oops, something went wrong.