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

feat: batch endpoints for column creation and retrieval #206

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

darora
Copy link
Contributor

@darora darora commented Mar 19, 2022

existing tests pass

@darora darora changed the title [wip] feat: batch endpoints for column creation and retrieval feat: batch endpoints for column creation and retrieval Mar 20, 2022
@@ -54,6 +55,26 @@ export default async (fastify: FastifyInstance) => {
return data
})

fastify.get<{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've opted to expose these separately rather than have the existing endpoints handle both cases; it gets annoying with the GET accepting a single ID param (and just gnarly in any case).

We can replace the current endpoint as part of a breaking change in the future.

Copy link
Contributor Author

@darora darora left a comment

Choose a reason for hiding this comment

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

Looks good! Couple of minor suggestions

if (!regexp.test(id)) {
return { data: null, error: { message: 'Invalid format for column ID' } }

const invalidId = ids.find((id) => !regexp.test(id))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would recommend findAll (or equivalent) here

Copy link
Member

Choose a reason for hiding this comment

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

👍

table,
schema = 'public',
}: {
ids?: string[]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really dislike this way of everything being optional - can we use a discriminated union type instead?

Copy link
Member

Choose a reason for hiding this comment

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

It's a TS thing - the 2 function declaration above it means it's either ids or names + table + schema

}),
body: Type.Union([postgresColumnCreateSchema, Type.Array(postgresColumnCreateSchema)]),
response: {
200: Type.Union([postgresColumnSchema, Type.Array(postgresColumnSchema)]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we wanted to be really nice about it, would be cool to pluck the table name out of the array, since we don't allow multiple different values for the field here anyway

Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to make the response format consistent: T | T[] for everything

Makes the Array.isArray check at the end always true
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.

2 participants