2023-01-27 02:21:12 +00:00
|
|
|
import ApplicationAdapter from '../application';
|
|
|
|
import { getUnixTime } from 'date-fns';
|
2020-10-01 19:37:33 +00:00
|
|
|
|
2023-01-27 02:21:12 +00:00
|
|
|
export default class ActivityAdapter extends ApplicationAdapter {
|
|
|
|
// javascript localizes new Date() objects but all activity log data is stored in UTC
|
|
|
|
// create date object from user's input using Date.UTC() then send to backend as unix
|
|
|
|
// time params from the backend are formatted as a zulu timestamp
|
|
|
|
formatQueryParams(queryParams) {
|
|
|
|
let { start_time, end_time } = queryParams;
|
|
|
|
start_time = start_time.timestamp || getUnixTime(Date.UTC(start_time.year, start_time.monthIdx, 1));
|
|
|
|
// day=0 for Date.UTC() returns the last day of the month before
|
|
|
|
// increase monthIdx by one to get last day of queried month
|
|
|
|
end_time = end_time.timestamp || getUnixTime(Date.UTC(end_time.year, end_time.monthIdx + 1, 0));
|
|
|
|
return { start_time, end_time };
|
|
|
|
}
|
2022-02-01 20:45:01 +00:00
|
|
|
|
|
|
|
queryRecord(store, type, query) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const url = `${this.buildURL()}/internal/counters/activity`;
|
2023-01-27 02:21:12 +00:00
|
|
|
const queryParams = this.formatQueryParams(query);
|
2022-02-01 20:45:01 +00:00
|
|
|
if (queryParams) {
|
|
|
|
return this.ajax(url, 'GET', { data: queryParams }).then((resp) => {
|
2022-11-09 23:15:31 +00:00
|
|
|
const response = resp || {};
|
2022-02-01 20:45:01 +00:00
|
|
|
response.id = response.request_id || 'no-data';
|
|
|
|
return response;
|
2022-01-25 22:06:56 +00:00
|
|
|
});
|
|
|
|
}
|
2023-01-27 02:21:12 +00:00
|
|
|
}
|
|
|
|
}
|