2020-01-13 05:47:03 +00:00
|
|
|
/* global axios */
|
2020-01-01 17:00:43 +00:00
|
|
|
import ApiClient from './ApiClient';
|
|
|
|
|
2021-06-18 14:38:58 +00:00
|
|
|
export const buildContactParams = (page, sortAttr, label, search) => {
|
2021-07-23 13:09:24 +00:00
|
|
|
let params = `include_contact_inboxes=false&page=${page}&sort=${sortAttr}`;
|
2021-06-18 14:38:58 +00:00
|
|
|
if (search) {
|
|
|
|
params = `${params}&q=${search}`;
|
|
|
|
}
|
|
|
|
if (label) {
|
|
|
|
params = `${params}&labels[]=${label}`;
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
};
|
|
|
|
|
2020-01-01 17:00:43 +00:00
|
|
|
class ContactAPI extends ApiClient {
|
|
|
|
constructor() {
|
2020-03-09 17:57:10 +00:00
|
|
|
super('contacts', { accountScoped: true });
|
2020-01-01 17:00:43 +00:00
|
|
|
}
|
2020-01-13 05:47:03 +00:00
|
|
|
|
2021-06-18 14:38:58 +00:00
|
|
|
get(page, sortAttr = 'name', label = '') {
|
|
|
|
let requestURL = `${this.url}?${buildContactParams(
|
|
|
|
page,
|
|
|
|
sortAttr,
|
|
|
|
label,
|
|
|
|
''
|
|
|
|
)}`;
|
|
|
|
return axios.get(requestURL);
|
2020-11-10 09:55:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 05:47:03 +00:00
|
|
|
getConversations(contactId) {
|
|
|
|
return axios.get(`${this.url}/${contactId}/conversations`);
|
|
|
|
}
|
2020-11-10 09:55:26 +00:00
|
|
|
|
2021-04-16 15:01:07 +00:00
|
|
|
getContactableInboxes(contactId) {
|
|
|
|
return axios.get(`${this.url}/${contactId}/contactable_inboxes`);
|
|
|
|
}
|
|
|
|
|
2021-06-14 05:06:00 +00:00
|
|
|
getContactLabels(contactId) {
|
|
|
|
return axios.get(`${this.url}/${contactId}/labels`);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateContactLabels(contactId, labels) {
|
|
|
|
return axios.post(`${this.url}/${contactId}/labels`, { labels });
|
|
|
|
}
|
|
|
|
|
2021-06-18 14:38:58 +00:00
|
|
|
search(search = '', page = 1, sortAttr = 'name', label = '') {
|
|
|
|
let requestURL = `${this.url}/search?${buildContactParams(
|
|
|
|
page,
|
|
|
|
sortAttr,
|
|
|
|
label,
|
|
|
|
search
|
|
|
|
)}`;
|
|
|
|
return axios.get(requestURL);
|
2020-11-10 09:55:26 +00:00
|
|
|
}
|
2021-09-29 06:31:58 +00:00
|
|
|
|
2021-12-03 03:12:44 +00:00
|
|
|
filter(page = 1, sortAttr = 'name', queryPayload) {
|
|
|
|
let requestURL = `${this.url}/filter?${buildContactParams(page, sortAttr)}`;
|
|
|
|
return axios.post(requestURL, queryPayload);
|
|
|
|
}
|
|
|
|
|
2021-09-29 06:31:58 +00:00
|
|
|
importContacts(file) {
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('import_file', file);
|
|
|
|
return axios.post(`${this.url}/import`, formData, {
|
|
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
|
|
});
|
|
|
|
}
|
2021-11-11 09:53:33 +00:00
|
|
|
|
|
|
|
destroyCustomAttributes(contactId, customAttributes) {
|
|
|
|
return axios.post(`${this.url}/${contactId}/destroy_custom_attributes`, {
|
|
|
|
custom_attributes: customAttributes,
|
|
|
|
});
|
|
|
|
}
|
2022-07-12 08:03:16 +00:00
|
|
|
|
|
|
|
destroyAvatar(contactId) {
|
|
|
|
return axios.delete(`${this.url}/${contactId}/avatar`);
|
|
|
|
}
|
2020-01-01 17:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new ContactAPI();
|