mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	 17ff1f11a7
			
		
	
	17ff1f11a7
	
	
	
		
			
			* feat: genearte report in a grid * refactor: update API usage * refactor: separate generate method * refactor: abstract transform_data * feat: annotate with comments * feat: add explicit timezone * feat: download data only in user timezone * fix: dates included in heatmap
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* global axios */
 | |
| import ApiClient from './ApiClient';
 | |
| 
 | |
| const getTimeOffset = () => -new Date().getTimezoneOffset() / 60;
 | |
| 
 | |
| class ReportsAPI extends ApiClient {
 | |
|   constructor() {
 | |
|     super('reports', { accountScoped: true, apiVersion: 'v2' });
 | |
|   }
 | |
| 
 | |
|   getReports({
 | |
|     metric,
 | |
|     from,
 | |
|     to,
 | |
|     type = 'account',
 | |
|     id,
 | |
|     groupBy,
 | |
|     businessHours,
 | |
|   }) {
 | |
|     return axios.get(`${this.url}`, {
 | |
|       params: {
 | |
|         metric,
 | |
|         since: from,
 | |
|         until: to,
 | |
|         type,
 | |
|         id,
 | |
|         group_by: groupBy,
 | |
|         business_hours: businessHours,
 | |
|         timezone_offset: getTimeOffset(),
 | |
|       },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getSummary(since, until, type = 'account', id, groupBy, businessHours) {
 | |
|     return axios.get(`${this.url}/summary`, {
 | |
|       params: {
 | |
|         since,
 | |
|         until,
 | |
|         type,
 | |
|         id,
 | |
|         group_by: groupBy,
 | |
|         business_hours: businessHours,
 | |
|       },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getConversationMetric(type = 'account', page = 1) {
 | |
|     return axios.get(`${this.url}/conversations`, {
 | |
|       params: {
 | |
|         type,
 | |
|         page,
 | |
|       },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getAgentReports({ from: since, to: until, businessHours }) {
 | |
|     return axios.get(`${this.url}/agents`, {
 | |
|       params: { since, until, business_hours: businessHours },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getConversationTrafficCSV() {
 | |
|     return axios.get(`${this.url}/conversation_traffic`, {
 | |
|       params: { timezone_offset: getTimeOffset() },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getLabelReports({ from: since, to: until, businessHours }) {
 | |
|     return axios.get(`${this.url}/labels`, {
 | |
|       params: { since, until, business_hours: businessHours },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getInboxReports({ from: since, to: until, businessHours }) {
 | |
|     return axios.get(`${this.url}/inboxes`, {
 | |
|       params: { since, until, business_hours: businessHours },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getTeamReports({ from: since, to: until, businessHours }) {
 | |
|     return axios.get(`${this.url}/teams`, {
 | |
|       params: { since, until, business_hours: businessHours },
 | |
|     });
 | |
|   }
 | |
| }
 | |
| 
 | |
| export default new ReportsAPI();
 |