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

[mds-agency] Removing version param from agency payload to conform with general v… #331

Merged
merged 4 commits into from
May 18, 2020

Conversation

janedotx
Copy link

…ersioninig policy.

PR Checklist

  • simple searchable title - [mds-db] Add PG env var, [config] Fix eslint config
  • briefly describe the changes in this PR
  • mark as draft if should not be merged
  • write tests for all new functionality

Impacts

  • Provider
  • Agency
  • Audit
  • Policy
  • Compliance
  • Daily
  • Native
  • Policy Author

packages/mds-agency/types.ts Outdated Show resolved Hide resolved
@@ -471,8 +460,7 @@ export const readStop = async (req: AgencyApiRequest, res: AgencyReadStopRespons
if (!recorded_stop) {
return res.status(404).send({ error: new NotFoundError('Stop not found') })
}
const { version } = res.locals
res.status(200).send({ version, ...recorded_stop })
res.status(200).send({ ...recorded_stop })

Choose a reason for hiding this comment

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

.send({ ...recorded_stop }) could just be .send(recorded_stop)

return res.status(201).send({
version
})
return res.status(201).send({})

Choose a reason for hiding this comment

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

Does res.sendStatus(201) work or does res.status(201).send({}) result in different content type headers?

Copy link
Author

Choose a reason for hiding this comment

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

It sends a different header. It takes out the charset: utf-8.

Copy link

@mdurling mdurling left a comment

Choose a reason for hiding this comment

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

Minor nits, but LGTM

@@ -31,7 +31,7 @@ export type ApiQuery<Q1 extends string, Q2 extends string[] = never> = {

export interface ApiResponse<L = unknown, B = unknown>
extends express.Response<
B | { error: unknown; error_description?: string; error_details?: string[] } | { errors: unknown[] } | {}
B | { error: unknown; error_description?: string; error_details?: string[] } | { errors: unknown[] }

Choose a reason for hiding this comment

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

Would it make sense to make this it's own interface

interface ApiErrorReponse {
  error: unknown
  error_description?: string
  error_details?: string[] 
}

And make the AprResponse <B | ApiErrorResponse | { errors: ApiErrorReponse[] }

@@ -149,8 +147,7 @@ export const getVehiclesByProvider = async (req: AgencyApiRequest, res: AgencyGe

try {
const response = await getVehicles(skip, take, url, req.query, provider_id)
const { version } = res.locals
return res.status(200).send({ version, ...response })
return res.status(200).send({ ...response })

Choose a reason for hiding this comment

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

Still not sure the new object syntax is required in all of these places { ...response } and response being equivalent and all.

Copy link
Author

Choose a reason for hiding this comment

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

It's the difference between { response: {...}} and { "vehicles": [ ... ] "links": { "first": "https://...", "last": "https://...", "prev": "https://...", "next": "https://..." }}, and the former is not in the spec.

Choose a reason for hiding this comment

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

There is no difference between .send({...response}) and .send(response) ... note that I didn't suggest .send({ response })

Choose a reason for hiding this comment

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

I agree with Michael, .send({ ...response }) and .send(response) are the same AFAIK

Copy link
Author

Choose a reason for hiding this comment

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

never mind. never mind.

@@ -11,8 +11,7 @@ export type AgencyApiRequest<P extends Params = ParamsDictionary> = ApiRequest<P

export type AgencyApiAccessTokenScopes = 'admin:all' | 'vehicles:read'

export type AgencyApiResponse<TBody = any> = ApiVersionedResponse<
AGENCY_API_SUPPORTED_VERSION,
export type AgencyApiResponse<TBody = any> = ApiResponse<

Choose a reason for hiding this comment

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

I think you can remove the = any (and thus the eslint warning) since a type is always specified below. Also, unknown is preferable to any for don't care scenarios.

Copy link

@macsj200 macsj200 left a comment

Choose a reason for hiding this comment

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

LGTM, could be good to get rid of the spreads if we can.

@janedotx janedotx merged commit f607f81 into develop May 18, 2020
janedotx added a commit that referenced this pull request May 18, 2020
@janedotx janedotx deleted the fix/remove-version-payload-from-agency branch May 18, 2020 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants