Skip to content

Commit

Permalink
fix(core): fix fetch resource type
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Mar 1, 2022
1 parent 8e616b3 commit 6c794ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const isParamsList = (params: any): params is QueryParamsList => {
}


const generateQueryStringParams = (params: QueryParamsRetrieve | QueryParamsList | undefined, res: ResourceType): { [key: string]: string } => {
const generateQueryStringParams = (params: QueryParamsRetrieve | QueryParamsList | undefined, res: string | ResourceType): { [key: string]: string } => {

debug('generate query string params: %O, %O', params, res)

Expand All @@ -40,7 +40,7 @@ const generateQueryStringParams = (params: QueryParamsRetrieve | QueryParamsList
if (params.include) qp['include'] = params.include.join(',')
// Fields
if (params.fields) {
if (Array.isArray(params.fields)) params.fields = { [res.type]: params.fields }
if (Array.isArray(params.fields)) params.fields = { [(res as ResourceType).type || res]: params.fields }
Object.entries(params.fields).forEach(([p, v]) => {
qp[`fields[${p}]`] = v.join(',')
})
Expand Down
2 changes: 1 addition & 1 deletion src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ResourceAdapter {
}


async fetch<R extends Resource>(resource: ResourceType, path: string, params?: QueryParams, options?: ResourcesConfig): Promise<R | ListResponse<R>> {
async fetch<R extends Resource>(resource: string | ResourceType, path: string, params?: QueryParams, options?: ResourcesConfig): Promise<R | ListResponse<R>> {

debug('fetch: %o, %O, %O', path, params || {}, options || {})

Expand Down

0 comments on commit 6c794ad

Please sign in to comment.