Skip to content

Error: 404 Not Found on options to Select, Where, OrderBy, Take #1

@je-martinez

Description

@je-martinez

Description

Hello guys, I noticed a bug on the URL when you try to use options like select, where, orderBy, and take, for example:

When you try to do something like this:

    const data = await repository.find({
      orderBy: {
        ID: 'asc',
      },
      where: {
        ID: `VALUE`,
      },
    })

The URL is this: https://api.airtable.com/v0/{BASE_ID}/{TABLE_NAME}&filterByFormula=AND({ID}='Value')&maxRecords=1

As you can see the main problem is this part &filterByFormula since on the select, where, orderBy, and take, when the incoming query param is the first one, something like this:

https://api.airtable.com/v0/{BASE_ID}/{TABLE_NAME}?filterByFormula=AND({ID}='Value')&maxRecords=1

It results in 404 since this URL is not valid for Airtable.

Solution

The easy fix would be to apply something like this to the validators:

// orderby-url.validator.ts
...
      const querySeparator = url?.includes('?') ? '&' : '?';
      url = `${url}${querySeparator}sort[${index}][field]=${item}&sort[${index}][direction]=${value}`;
...
// select-url.validator.ts
...
      const querySeparator = url?.includes('?') ? '&' : '?';
      url = `${url}${querySeparator}fields[]=${String(item)}`;
...
// take-url.validator.ts
...
    const querySeparator = url?.includes('?') ? '&' : '?';
    return `${url}${querySeparator}maxRecords=${dataInstance.take}`;
...
// where-url.validator.ts
...
    const querySeparator = url?.includes('?') ? '&' : '?';
    url = `${url}${querySeparator}filterByFormula=`;
...

Note: I tried to create a branch and submit a PR w/ the fix, but for some reason, it's returning ...ERROR: Permission to ThinkAM/typeairtable.git denied... I'm new on GH contributions but I hope this helps others with these issues.

This is a great project guys, really helpful for those who want to use an ORM for Airtable. 🚀

Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions