Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WAITP-1318 Add single entity request route #4738

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/tupaia-web-server/src/app/createApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
EntitySearchRoute,
EntitySearchRequest,
RequestCountryAccessRequest,
EntityRoute,
EntityRequest,
} from '../routes';

const { WEB_CONFIG_API_URL = 'http://localhost:8000/api/v1' } = process.env;
Expand Down Expand Up @@ -69,6 +71,7 @@ export function createApp() {
'requestCountryAccess',
handleWith(RequestCountryAccessRoute),
)
.get<EntityRequest>('entity/:projectCode/:entityCode', handleWith(EntityRoute))
.get<EntitiesRequest>('entities/:projectCode/:rootEntityCode', handleWith(EntitiesRoute))
.get<EntitySearchRequest>('entitySearch/:projectCode', handleWith(EntitySearchRoute))
.get<EntitiesRequest>('entities/:projectCode/:rootEntityCode', handleWith(EntitiesRoute))
Expand Down
27 changes: 27 additions & 0 deletions packages/tupaia-web-server/src/routes/EntityRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/

import { Request } from 'express';
import { Route } from '@tupaia/server-boilerplate';
import camelCaseKeys from 'camelcase-keys';

// TODO: WAITP-1278 Move this to types
export type EntityRequest = Request<any, any, any, any>;
Comment on lines +10 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4731 is in progress but having some issues in codeship to fixup, if we merge this first, I'll make the update on that branch


const DEFAULT_FIELDS = ['parent_code', 'code', 'name', 'type'];

export class EntityRoute extends Route<EntityRequest> {
public async buildResponse() {
const { params, query, ctx } = this.req;
const { projectCode, entityCode } = params;

const entity = await ctx.services.entity.getEntity(projectCode, entityCode, {
fields: DEFAULT_FIELDS,
...query,
});

return camelCaseKeys(entity);
}
}
1 change: 1 addition & 0 deletions packages/tupaia-web-server/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

export { DashboardsRequest, DashboardsRoute } from './DashboardsRoute';
export { EntityRequest, EntityRoute } from './EntityRoute';
export { EntitiesRequest, EntitiesRoute } from './EntitiesRoute';
export { EntitySearchRequest, EntitySearchRoute } from './EntitySearchRoute';
export { EntityAncestorsRequest, EntityAncestorsRoute } from './EntityAncestorsRoute';
Expand Down