Skip to content

Commit

Permalink
fix: add meta deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
iacoshoria committed Oct 15, 2020
1 parent 3e53c83 commit c77b091
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 118 deletions.
34 changes: 23 additions & 11 deletions packages/earth-admin/src/services/dashboards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,50 @@
import { isString, merge } from 'lodash/fp';
import qs from 'query-string';

import { BaseAPIService, RequestQuery } from './base/APIBase';
import { BaseAPIService, metaDeserializer, RequestQuery } from './base/APIBase';

const getAllDashboards = async (query?: string | RequestQuery) => {
if (isString(query)) {
query = qs.parse(query);
}
return BaseAPIService.request('/dashboards', { query });
return BaseAPIService.request('/dashboards', { query }, metaDeserializer);
};

const addDashboard = async (data: any, query?: RequestQuery) => {
return BaseAPIService.request('/dashboards', { query, method: 'post', data });
return BaseAPIService.request('/dashboards', { query, method: 'post', data }, metaDeserializer);
};

const getDashboard = async (dashboardId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/dashboards/${dashboardId}`, { query });
return BaseAPIService.request(`/dashboards/${dashboardId}`, { query }, metaDeserializer);
};

const updateDashboard = async (dashboardId: string, data: any, query?: RequestQuery) => {
return BaseAPIService.request(`/dashboards/${dashboardId}`, {
method: 'put',
data,
query,
});
return BaseAPIService.request(
`/dashboards/${dashboardId}`,
{
method: 'put',
data,
query,
},
metaDeserializer
);
};

const deleteDashboards = async (dashboardId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/dashboards/${dashboardId}`, { query, method: 'delete' });
return BaseAPIService.request(
`/dashboards/${dashboardId}`,
{ query, method: 'delete' },
metaDeserializer
);
};

const getDashboardSlug = async (keyword: string, query?: RequestQuery) => {
const params = { keyword, type: 'counter' };
return BaseAPIService.request('/dashboards/slug', { query: merge(params, query) });
return BaseAPIService.request(
'/dashboards/slug',
{ query: merge(params, query) },
metaDeserializer
);
};

const handleDashboardForm = async (
Expand Down
22 changes: 15 additions & 7 deletions packages/earth-admin/src/services/layers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,42 @@
import { isString, merge } from 'lodash/fp';
import qs from 'query-string';

import { BaseAPIService, RequestQuery } from './base/APIBase';
import { BaseAPIService, metaDeserializer, RequestQuery } from './base/APIBase';

const getAllLayers = async (query?: string | RequestQuery) => {
if (isString(query)) {
query = qs.parse(query);
}
return BaseAPIService.request('/layers', { query });
return BaseAPIService.request('/layers', { query }, metaDeserializer);
};

const addLayer = async (data: any, query?: RequestQuery) => {
return BaseAPIService.request('/layers', { query, method: 'post', data });
return BaseAPIService.request('/layers', { query, method: 'post', data }, metaDeserializer);
};

const getLayer = (layerId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/layers/${layerId}`, { query });
return BaseAPIService.request(`/layers/${layerId}`, { query }, metaDeserializer);
};

const updateLayer = async (layerId: string, data: any, query?: RequestQuery) => {
return BaseAPIService.request(`/layers/${layerId}`, { query, method: 'put', data });
return BaseAPIService.request(
`/layers/${layerId}`,
{ query, method: 'put', data },
metaDeserializer
);
};

const deleteLayer = async (layerId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/layers/${layerId}`, { query, method: 'delete' });
return BaseAPIService.request(
`/layers/${layerId}`,
{ query, method: 'delete' },
metaDeserializer
);
};

const getLayerSlug = async (keyword: string, query?: RequestQuery) => {
const params = { keyword, type: 'counter' };
return BaseAPIService.request('/layers/slug', { query: merge(params, query) });
return BaseAPIService.request('/layers/slug', { query: merge(params, query) }, metaDeserializer);
};

const handleLayerForm = async (
Expand Down
28 changes: 18 additions & 10 deletions packages/earth-admin/src/services/metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { merge } from 'lodash/fp';

import { BaseAPIService, RequestQuery } from './base/APIBase';
import { BaseAPIService, metaDeserializer, RequestQuery } from './base/APIBase';

interface ResponseSuccess {
operationId?: string;
Expand All @@ -40,10 +40,14 @@ const calculateAllForPlace = async (
query?: RequestQuery
): Promise<ResponseSuccess | ResponseError> => {
const params = { operationType: 'calculate' };
return BaseAPIService.request(`/metrics/${placeId}/action`, {
query: merge(params, query),
method: 'post',
});
return BaseAPIService.request(
`/metrics/${placeId}/action`,
{
query: merge(params, query),
method: 'post',
},
metaDeserializer
);
};

const calculateForPlace = async (
Expand All @@ -52,14 +56,18 @@ const calculateForPlace = async (
query?: RequestQuery
): Promise<ResponseSuccess | ResponseError> => {
const params = { operationType: 'calculate' };
return BaseAPIService.request(`/metrics/${placeId}/${metricId}/action`, {
query: merge(params, query),
method: 'post',
});
return BaseAPIService.request(
`/metrics/${placeId}/${metricId}/action`,
{
query: merge(params, query),
method: 'post',
},
metaDeserializer
);
};

const getAllMetrics = async (query?: RequestQuery) => {
return BaseAPIService.request('/metrics', { query });
return BaseAPIService.request('/metrics', { query }, metaDeserializer);
};

export default { calculateAllForPlace, calculateForPlace, getAllMetrics };
40 changes: 26 additions & 14 deletions packages/earth-admin/src/services/organizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,53 @@
import { isString, merge } from 'lodash/fp';
import qs from 'query-string';

import { BaseAPIService, RequestQuery } from './base/APIBase';
import { BaseAPIService, metaDeserializer, RequestQuery } from './base/APIBase';

const getAllOrganizations = async (query?: string | RequestQuery) => {
if (isString(query)) {
query = qs.parse(query);
}
return BaseAPIService.request('/organizations', { query });
return BaseAPIService.request('/organizations', { query }, metaDeserializer);
};

const getOrganization = (orgId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/organizations/${orgId}`, { query });
return BaseAPIService.request(`/organizations/${orgId}`, { query }, metaDeserializer);
};

const getOrganizationStats = async (query?: RequestQuery) => {
return BaseAPIService.request('/organization/stats', { query });
return BaseAPIService.request('/organizations/stats', { query, metaDeserializer });
};

const updateOrganization = async (orgId: string, data: any, query?: RequestQuery) => {
const params = { include: 'owners' };
return BaseAPIService.request(`/organizations/${orgId}`, {
query: merge(params, query),
method: 'put',
data,
});
return BaseAPIService.request(
`/organizations/${orgId}`,
{
query: merge(params, query),
method: 'put',
data,
},
metaDeserializer
);
};

const addOrganization = async (data: any, query?: RequestQuery) => {
return BaseAPIService.request('/organizations', { query, method: 'post', data });
return BaseAPIService.request(
'/organizations',
{ query, method: 'post', data },
metaDeserializer
);
};

const deleteOrganization = async (orgId, query?: RequestQuery) => {
return BaseAPIService.request(`/organizations/${orgId}`, {
method: 'delete',
query,
});
return BaseAPIService.request(
`/organizations/${orgId}`,
{
method: 'delete',
query,
},
metaDeserializer
);
};

export default {
Expand Down
60 changes: 40 additions & 20 deletions packages/earth-admin/src/services/places.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,67 @@
import { isString, merge } from 'lodash/fp';
import qs from 'query-string';

import { BaseAPIService, RequestQuery } from './base/APIBase';
import { BaseAPIService, metaDeserializer, RequestQuery } from './base/APIBase';

const getAllPlaces = async (query?: string | RequestQuery) => {
if (isString(query)) {
query = qs.parse(query);
}
return BaseAPIService.request('/locations', { query });
return BaseAPIService.request('/locations', { query }, metaDeserializer);
};

const addPlace = async (data: any, query?: RequestQuery) => {
return BaseAPIService.request('/locations', {
query,
method: 'post',
data,
});
return BaseAPIService.request(
'/locations',
{
query,
method: 'post',
data,
},
metaDeserializer
);
};

const getPlace = (placeId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/locations/${placeId}`, {
query,
});
return BaseAPIService.request(
`/locations/${placeId}`,
{
query,
},
metaDeserializer
);
};

const updatePlace = async (placeId: string, data: any, query?: RequestQuery) => {
return BaseAPIService.request(`/locations/${placeId}`, {
method: 'put',
data,
query,
});
return BaseAPIService.request(
`/locations/${placeId}`,
{
method: 'put',
data,
query,
},
metaDeserializer
);
};

const deletePlace = async (placeId: string, query?: RequestQuery) => {
return BaseAPIService.request(`/locations/${placeId}`, {
method: 'delete',
query,
});
return BaseAPIService.request(
`/locations/${placeId}`,
{
method: 'delete',
query,
},
metaDeserializer
);
};

const getPlaceSlug = async (keyword: string, query?: RequestQuery) => {
const params = { keyword, type: 'counter' };
return BaseAPIService.request('/locations/slug', { query: merge(params, query) });
return BaseAPIService.request(
'/locations/slug',
{ query: merge(params, query) },
metaDeserializer
);
};

const handlePlaceForm = async (
Expand Down
Loading

0 comments on commit c77b091

Please sign in to comment.