-
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.
RN-1060: Added dashboards/:project/:entity/:dashboard/export route to…
… tupaia-web
- Loading branch information
Rohan Port
committed
Oct 30, 2023
1 parent
ee6fe0a
commit b36359d
Showing
7 changed files
with
70 additions
and
8 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
36 changes: 36 additions & 0 deletions
36
packages/tupaia-web-server/src/routes/ExportDashboardRoute.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,36 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
* | ||
*/ | ||
|
||
import { Request } from 'express'; | ||
import { Route } from '@tupaia/server-boilerplate'; | ||
import { TupaiaWebExportDashboardRequest } from '@tupaia/types'; | ||
import { downloadPageAsPDF } from '@tupaia/tsutils'; | ||
import { stringifyQuery } from '@tupaia/utils'; | ||
|
||
export type ExportDashboardRequest = Request< | ||
TupaiaWebExportDashboardRequest.Params, | ||
TupaiaWebExportDashboardRequest.ResBody, | ||
TupaiaWebExportDashboardRequest.ReqBody, | ||
TupaiaWebExportDashboardRequest.ReqQuery | ||
>; | ||
|
||
export class ExportDashboardRoute extends Route<ExportDashboardRequest> { | ||
protected type = 'download' as const; | ||
|
||
public async buildResponse() { | ||
const { projectCode, entityCode, dashboardName } = this.req.params; | ||
const { baseUrl, selectedDashboardItems, cookieDomain } = this.req.body; | ||
const { cookie } = this.req.headers; | ||
|
||
const endpoint = `${projectCode}/${entityCode}/${dashboardName}/pdf-export`; | ||
const pdfPageUrl = stringifyQuery(baseUrl, endpoint, { | ||
selectedDashboardItems: selectedDashboardItems?.join(','), | ||
}); | ||
|
||
const buffer = await downloadPageAsPDF(pdfPageUrl, cookie, cookieDomain); | ||
return { contents: buffer, type: 'application/pdf' }; | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
packages/types/src/types/requests/tupaia-web-server/ExportDashboardRequest.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,21 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
export interface Params { | ||
projectCode: string; | ||
entityCode: string; | ||
dashboardName: string; | ||
} | ||
export interface ResBody { | ||
contents: Buffer; | ||
filePath?: string; | ||
type: string; | ||
} | ||
export type ReqBody = { | ||
cookieDomain: string; | ||
baseUrl: string; | ||
selectedDashboardItems?: string[]; | ||
}; | ||
export type ReqQuery = Record<string, string>; |
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