forked from Greenstand/treetracker-admin-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathearnings.js
More file actions
51 lines (46 loc) · 1.18 KB
/
earnings.js
File metadata and controls
51 lines (46 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { authAxios } from './httpClient';
const apiUrl = `${process.env.REACT_APP_EARNINGS_ROOT}`;
export default {
/**
* @function getEarnings
* @description Get earnings from the API
* @returns {Promise}
*/
async getEarnings(params) {
return authAxios
.get(`${apiUrl}/earnings`, { params })
.then((res) => res.data);
},
/**
* @function patchEarning
* @description Patch earning from the API
*
* @param {object} earning - earning to patch
* @returns {Promise}
*/
async patchEarning(earning) {
return authAxios
.patch(`${apiUrl}/earnings`, earning)
.then((res) => res.data);
},
/**
* @funtion batchPatchEarnings
* @description Batch patch earnings
* @param {File} csv file
* @returns {Promise}
* */
async batchPatchEarnings(file) {
const formData = new FormData();
formData.append('csv', file);
return authAxios
.patch(`${apiUrl}/earnings/batch`, formData, {
headers: {
accept: 'multipart/form-data',
},
})
.then((res) => res.data)
.catch((error) => {
throw new Error('Payments Batch Upload Failed!', { cause: error });
});
},
};