Make analytics endpoint a GET endpoint
[MAILPOET-5088]
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import apiFetch from '@wordpress/api-fetch';
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
import { dispatch, select } from '@wordpress/data';
|
import { dispatch, select } from '@wordpress/data';
|
||||||
import { getCurrentDates } from '@woocommerce/date';
|
import { getCurrentDates } from '@woocommerce/date';
|
||||||
|
import {addQueryArgs} from "@wordpress/url";
|
||||||
import { api } from '../config';
|
import { api } from '../config';
|
||||||
import { storeName } from '../store/constants';
|
import { storeName } from '../store/constants';
|
||||||
import { Query, Section, SectionData } from '../store/types';
|
import { Query, Section, SectionData } from '../store/types';
|
||||||
@ -37,12 +38,12 @@ export async function updateSection(
|
|||||||
|
|
||||||
const dates = {
|
const dates = {
|
||||||
primary: {
|
primary: {
|
||||||
after: primaryDate.after.toDate(),
|
after: primaryDate.after.toDate().toISOString(),
|
||||||
before: primaryDate.before.toDate(),
|
before: primaryDate.before.toDate().toISOString(),
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
after: secondaryDate.after.toDate(),
|
after: secondaryDate.after.toDate().toISOString(),
|
||||||
before: secondaryDate.before.toDate(),
|
before: secondaryDate.before.toDate().toISOString(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,15 +52,14 @@ export async function updateSection(
|
|||||||
...section,
|
...section,
|
||||||
data: undefined,
|
data: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const path = addQueryArgs(section.endpoint, {id, query: dates})
|
||||||
|
const method = 'GET';
|
||||||
const response: {
|
const response: {
|
||||||
data: SectionData;
|
data: SectionData;
|
||||||
} = await apiFetch({
|
} = await apiFetch({
|
||||||
path: section.endpoint,
|
path,
|
||||||
method: 'POST',
|
method,
|
||||||
data: {
|
|
||||||
query: dates,
|
|
||||||
id,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch(storeName).setSectionData({
|
dispatch(storeName).setSectionData({
|
||||||
|
@ -20,7 +20,7 @@ class Analytics {
|
|||||||
|
|
||||||
public function register(): void {
|
public function register(): void {
|
||||||
$this->wordPress->addAction(Hooks::API_INITIALIZE, function (API $api) {
|
$this->wordPress->addAction(Hooks::API_INITIALIZE, function (API $api) {
|
||||||
$api->registerPostRoute('automation/analytics/overview', OverviewEndpoint::class);
|
$api->registerGetRoute('automation/analytics/overview', OverviewEndpoint::class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user