| 1 |
import { Period } from './constants'; |
| 2 |
import { removeDaysFromDate } from './date'; |
| 3 |
|
| 4 |
export interface AnalyticsApiQueryParams extends AnalyticsApiOptionalQueryParams { |
| 5 |
type: string, |
| 6 |
} |
| 7 |
|
| 8 |
export interface AnalyticsApiOptionalQueryParams extends ApiPeriodRange { |
| 9 |
pub_date_start?: string; |
| 10 |
pub_date_end?: string; |
| 11 |
sort?: string; |
| 12 |
limit?: number; |
| 13 |
page?: number; |
| 14 |
author?: string; |
| 15 |
tag?: string; |
| 16 |
section?: string; |
| 17 |
segment?: string; |
| 18 |
} |
| 19 |
|
| 20 |
export interface ApiPeriodRange { |
| 21 |
period_start?: string; // Defaults to 3 days ago. |
| 22 |
period_end?: string; // Defaults to current date and time. |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Gets `period_start` and `period_end` params for API. |
| 27 |
* |
| 28 |
* @param {Period} period Number of days for which to calculate the period range. |
| 29 |
* |
| 30 |
* @return {ApiPeriodRange} API query params. |
| 31 |
*/ |
| 32 |
export function getApiPeriodParams( period: Period ): ApiPeriodRange { |
| 33 |
return { |
| 34 |
period_start: period, |
| 35 |
period_end: '', |
| 36 |
}; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Gets period start date for API. |
| 41 |
* |
| 42 |
* @param {number} days Number of days for which to calculate the period start |
| 43 |
* date. |
| 44 |
* |
| 45 |
* @return {string} period start date. |
| 46 |
*/ |
| 47 |
export function getApiPeriodStartDate( days: number ): string { |
| 48 |
return removeDaysFromDate( new Date(), days - 1 ) + 'T00:00'; |
| 49 |
} |
| 50 |
|