Code coverage report for app/pages/phone/phone.service.js

Statements: 100% (67 / 67)      Branches: 100% (30 / 30)      Functions: 100% (16 / 16)      Lines: 100% (43 / 43)      Ignored: 2 statements, 4 branches     

All files » app/pages/phone/ » phone.service.js
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95   16×   16×                                                                                                      
const errorHandler = Symbol();
class PhoneService {
    constructor ($http, $q, AjaxError) {
        Object.assign(this, {$http, $q, AjaxError});
 
        this[errorHandler] = this.AjaxError.catcher.bind(this.AjaxError);
    }
 
    getPhones () {
        const self = this;
        return this.$http.get('api/phones')
            .then(_success)
            .catch(this[errorHandler]);
 
        function _success (response) {
            const data = response.data;
            if (response.status === 200 && data.code === 0) {
                return data.result.phones;
            }
            return self.$q.reject(data.message);
        }
    }
 
    getPhoneDetail (id) {
        const self = this;
        return this.$http.get(`api/phones/${id}`)
            .then(_success)
            .catch(this[errorHandler]);
 
        function _success (response) {
            const data = response.data;
            if (response.status === 200 && data.code === 0) {
                return data.result.phone;
            }
            return self.$q.reject(data.message);
        }
    }
 
    addNewPhone (phone) {
        const self = this;
        const req = {
            phone
        };
        return this.$http.post('api/phones', req)
            .then(_success)
            .catch(this[errorHandler]);
 
        function _success (response) {
            const data = response.data;
            if (response.status === 200 && data.code === 0) {
                return data.result.phone;
            }
            return self.$q.reject(data.message);
        }
    }
 
    updatePhone (id, phone) {
        const self = this;
        const req = {
            phone
        };
        return this.$http.put(`api/phones/${id}`, req)
            .then(_success)
            .catch(this[errorHandler]);
 
        function _success (response) {
            const data = response.data;
            if (response.status === 200 && data.code === 0) {
                return data.result.phone;
            }
            return self.$q.reject(data.message);
        }
    }
 
    removePhone (id) {
        const self = this;
        return this.$http.delete(`api/phones/${id}`)
            .then(_success)
            .catch(this[errorHandler]);
 
        function _success (response) {
            const data = response.data;
            if (response.status === 200 && data.code === 0) {
                return data.result.phone;
            }
            return self.$q.reject(data.message);
        }
    }
}
 
PhoneService.$inject = ['$http', '$q', 'AjaxErrorHandler'];
 
export default PhoneService;