Skip to content

Commit

Permalink
feat: dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stbui committed Aug 22, 2019
1 parent 0338ef3 commit 462383c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/data-json-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { GET_LIST, GET_ONE, CREATE, UPDATE, DELETE } from 'prophet-core';
import { crudMetadata } from 'prophet-common';
import { stringify } from 'query-string';

export default (apiUrl: string, httpClient = fetch) => {
return (
type: crudMetadata,
type: any,
resource: string,
params: any
): Promise<any> => {
let url: string = '';

switch (type) {
case GET_LIST:
const { pagination, filter, ...ohter } = params;
const { page, perPage } = params.pagination;
const { field, order } = params.sort;

const query = {
...filter,
...ohter,
...params.filter,
sort: field,
order: order,
page: page,
perPage: perPage
};

if (pagination) {
const { page, perPage } = pagination;
query.page = page;
query.perPage = perPage;
}

url = `${apiUrl}/${resource}?${stringify(query)}`;
return httpClient(url)
.then(resopnse => resopnse.json())
Expand Down

0 comments on commit 462383c

Please sign in to comment.