Skip to content

Commit

Permalink
feat: add custom presenter to the render controller method
Browse files Browse the repository at this point in the history
  • Loading branch information
gridcat committed Nov 25, 2021
1 parent b62e5bf commit 2057e60
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/grc-stamp/src/controllers/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,20 @@ export class Controller {
// return value && typeof value === 'object' && value.constructor === Object;
}

public render<T>(data: T | RepoListResults<T>): Record<string, unknown> {
public render<T>(
data: T | RepoListResults<T>,
customPresenter?: PresenterInterface,
): Record<string, unknown> {
const presenter = customPresenter || this.presenter;
if (this.isObject(data) && 'rows' in data) {
const meta = {
count: 0,
};
if (data.count) {
meta.count = data.count as number;
}
return this.presenter.render(data.rows, { meta });
return presenter.render(data.rows, { meta });
}
return this.presenter.render(data);
return presenter.render(data);
}
}

0 comments on commit 2057e60

Please sign in to comment.