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

feature request: support array type query. #301

Closed
rojiwon123 opened this issue Apr 9, 2023 · 1 comment
Closed

feature request: support array type query. #301

rojiwon123 opened this issue Apr 9, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@rojiwon123
Copy link
Contributor

rojiwon123 commented Apr 9, 2023

express는 쿼리 값에 대해 같은 키로 전달되면 배열형태로 전달합니다.
하지만 현재 nestia sdk는 쿼리키에 대해 복수의 값을 전달할 수 없습니다.

URLSearchParams는 인자로 string[][] 타입을 전달받을 수 있고, 이 경우 내부 배열의 첫 요소는 key, 두번째 요소는 value가 됩니다.ex) [ [key, value], [key, value] ]

그래서 이를 위해 sdk 쿼리 생성 로직을 아래처럼 변경하는 것을 제안합니다.


The express module supports array format for query parameters.

example)
query: https:example.com?item=1&item=2&item=3
=> express.Request.query.item = ['1', '2', '3']

so I think, the SDK also requires logic to generate queries in the format mentioned above for array values.

URLSearchParams provides a way to generate such queries using the following approach.

new URLSearchParams([ ['key1', 'value1'], ['key2', 'value2'], ['key1', 'value3'] ]);

// key1=value1&key2=value2&key1=value3

// in express, query.key1 is ['value1', 'value3'], query.key2 is 'value2'

The following code is my proposed solution.

export function path(status: Array<string>, methods: Array<string>, pg_providers: Array<string>, query: IPayment.FindManyQuery): string
    {
        const querys: string[][] = [];
        const variables= 
        {
            ...query,      // this value is object type
            status,        // this value is string[]
            methods,       // this value is string[]
            pg_providers,  // this value is string[]
        };
        for (const [key, value] of Object.entries(variables)){
            if(Array.isArray(value)) {
                value.forEach(v=>querys.push([key, v]));
            }else if(value !== undefined) {
                querys.push([key, value as string]);
            }
        }
        const encoded: string = new URLSearchParams(querys).toString();

        
        return `/payments?${encoded}`;
    }
}
@samchon samchon self-assigned this Apr 10, 2023
@samchon samchon added enhancement New feature or request good first issue Good for newcomers labels Apr 10, 2023
@samchon
Copy link
Owner

samchon commented Apr 10, 2023

Good point, it will be supported at next week.

samchon added a commit that referenced this issue Apr 13, 2023
Close #301 - `TypedQuery` supports array type
samchon added a commit that referenced this issue Apr 26, 2023
Complement #301 - `TypedQuery()` allow nullable types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants