Blame view
src/Services/ApiCalls.js
4.05 KB
6f7cf8cf5
|
1 2 3 |
import http from "@/Services/http.js"; import Rules from "@/pages/Common/rules.js" export default { |
860da881d
|
4 5 6 |
mixins: [Rules], data() { return { |
6f7cf8cf5
|
7 |
|
860da881d
|
8 9 10 11 12 13 14 15 16 17 18 |
// LOADER showLoader: false, loading: false, // SNACKBAR snackbar: false, snackbarColor: '', text: '', timeout: 4000, y: "top", x: "right", mode: "", |
6f7cf8cf5
|
19 |
|
860da881d
|
20 21 22 23 24 |
// PAGINATION size: 10, elements: "", pageCount: "", pageNumber: 0 |
6f7cf8cf5
|
25 |
|
860da881d
|
26 27 28 29 30 31 32 33 34 35 |
} }, methods: { // SNACKBAR seeSnackbar(message, color) { this.text = message; this.showLoader = false; this.snackbarColor = color; this.snackbar = true; }, |
6f7cf8cf5
|
36 |
|
860da881d
|
37 38 39 40 41 42 43 44 45 46 47 48 49 |
// SET PAGINATION setPagination(response) { this.elements = response.data.totalElements; var l = this.elements; var s = this.size; var floor = (l / s); this.pageCount = Math.floor(floor); if (this.pageCount == floor) { this.pageCount -= 1 } this.showLoader = false; this.loading = false; }, |
6f7cf8cf5
|
50 |
|
860da881d
|
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 |
generateError(error) { var customError const errorNo = error.response.status // console.log("satus code errorNo", errorNo) switch (errorNo) { case 400: let er = error if (er.response.data.error) { customError = error.response.data.error } if (er.response.data.errorMessage) { customError = error.response.data.errorMessage } if (er.response.data.message) { customError = error.response.data.message } return customError break; case 401: customError = "Session expired" return customError break; case 404: customError = error.response.data.errorMessage return customError break; case 409: customError = error.response.data.errorMessage return customError break; case 500: customError = error.response.data.message return customError break; default: customError = "unknown error" return customError } |
6f7cf8cf5
|
89 |
|
860da881d
|
90 |
}, |
6f7cf8cf5
|
91 |
|
860da881d
|
92 93 94 95 96 97 |
// GET getMethod(url, params) { this.showLoader = true return http() .get(url, { params: params, |
6f7cf8cf5
|
98 |
|
860da881d
|
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
headers: { // headers: { Authorization: "Bearer " + this.token } } }) .then(response => { this.showLoader = false return response }) .catch(error => { this.showLoader = false // console.log("error in getMethod = ", error.response) const message = this.generateError(error) if (message == "Session expired") { // this.$store.dispatch("setToken", null); // this.$router.push({ // name: 'Login' // }); } else { throw new Error(message); } |
6f7cf8cf5
|
119 |
|
860da881d
|
120 121 |
}); }, |
6f7cf8cf5
|
122 |
|
860da881d
|
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
// POST postMethod(url, payload) { this.showLoader = true return http() .post(url, payload, { // headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.showLoader = false return response }) .catch(error => { this.showLoader = false // console.log("error in postMethod = ", error.response) const message = this.generateError(error) if (message == "Session expired") { this.$store.dispatch("setToken", null); this.$router.push({ name: 'Login' }); } else { throw new Error(message); } |
6f7cf8cf5
|
146 |
|
860da881d
|
147 148 |
}); }, |
6f7cf8cf5
|
149 |
|
860da881d
|
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
// PUT putMethod(url, payload) { return http() .put(url, payload, { // headers: { // // Authorization: 'Bearer ' + this.token // } }) .then(response => { return response }) .catch(error => { // console.log("error in putMethod = ", error.response) const message = this.generateError(error) if (message == "Session expired") { this.$store.dispatch("setToken", null); this.$router.push({ name: 'Login' }); } else { throw new Error(message); } |
6f7cf8cf5
|
172 |
|
860da881d
|
173 174 |
}) } |
6f7cf8cf5
|
175 |
|
860da881d
|
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
}, computed: { displayedPageNumber() { return this.pageNumber + 1; }, // managerIsADMIN_VIEW: { // get() { // if (this.$store.state.roleName == "ADMIN_VIEW") { // return true; // } else { // return false // } // }, // set(newValue) { // this.managerIsADMIN_VIEW = newValue; // } |
6f7cf8cf5
|
192 |
|
860da881d
|
193 194 |
// } }, |
6f7cf8cf5
|
195 |
} |