3838<script >
3939import cloneDeep from ' lodash.clonedeep' ;
4040import FormDataValues from ' ./../mixins/formDataValues' ;
41- import {destroy , get , post , put } from ' ../api/implementation/app' ;
42- import objectToFormData from ' ../api/util/objectToFormDataConverter.js' ;
41+ import axios from ' ../api/implementation/app' ;
4342
4443export default {
4544 components: {},
@@ -141,15 +140,15 @@ export default {
141140 desc: sortDesc[0 ] ? 1 : 0 ,
142141 };
143142 }
144- get (this .resourceUri , {
145- q: search,
146- page: page,
147- perPage: itemsPerPage,
148- ... sorting,
149- })
150- .then (( response ) => {
151- const items = this .mapDataResponse (response .data );
152- const total = response .data .meta .total ;
143+ axios . get (this .resourceUri , {
144+ q: search,
145+ page: page,
146+ perPage: itemsPerPage,
147+ ... sorting,
148+ })
149+ .then (res => {
150+ const items = this .mapDataResponse (res . data .data );
151+ const total = res .data .meta .total ;
153152 resolve ({
154153 items,
155154 total,
@@ -160,7 +159,7 @@ export default {
160159 },
161160 getItemFromApi (id ) {
162161 return new Promise ((resolve ) => {
163- get ((this .showResourceUri || this .resourceUri ) + ' /' + id)
162+ axios . get ((this .showResourceUri || this .resourceUri ) + ' /' + id)
164163 .then ((response ) => {
165164 const item = response .data .data ;
166165 resolve ({
@@ -183,21 +182,18 @@ export default {
183182 return new Promise ((resolve , reject ) => {
184183 process .nextTick (() => {
185184 if (this .createForm .valid ) {
186- post ((this .createResourceUri || this .resourceUri ), objectToFormData (this .getCreateFormValues ()))
187- .then ((response ) => {
188- console .log (' createEvent: ' );
189- console .log (response .data );
185+ axios .post ((this .createResourceUri || this .resourceUri ), this .getCreateFormValues ())
186+ .then (res => {
190187 this .createForm .values = {};
191188 if (typeof this .afterCreate === ' function' ) {
192- this .afterCreate (response .data .data ).then (() => {
189+ this .afterCreate (res .data .data ).then (() => {
193190 resolve ();
194191 });
195192 } else {
196193 resolve ();
197194 }
198195 }).catch ((error ) => {
199- console .log (error);
200- this .errors = error .response .data .errors ;
196+ this .errors = error .data .errors ;
201197 reject ();
202198 });
203199
@@ -220,20 +216,17 @@ export default {
220216 return new Promise ((resolve , reject ) => {
221217 process .nextTick (() => {
222218 if (this .updateForm .valid ) {
223- put ((this .updateResourceUri || this .resourceUri ) + ' /' + selected[0 ].id , objectToFormData (this .getUpdateFormValues ()))
224- .then ((response ) => {
225- console .log (' updateEvent: ' );
226- console .log (response .data );
219+ axios .put ((this .updateResourceUri || this .resourceUri ) + ' /' + selected[0 ].id , this .getUpdateFormValues ())
220+ .then (res => {
227221 if (typeof this .afterUpdate === ' function' ) {
228- this .afterUpdate (response .data ).then (() => {
222+ this .afterUpdate (res . data .data ).then (() => {
229223 resolve ();
230224 });
231225 } else {
232226 resolve ();
233227 }
234228 }).catch ((error ) => {
235- console .log (error);
236- this .errors = error .response .data .errors ;
229+ this .errors = error .data .errors ;
237230 reject ();
238231 });
239232
@@ -248,7 +241,7 @@ export default {
248241 deleteEvent (ids ) {
249242 return new Promise ((resolve ) => {
250243 const promises = [];
251- ids .forEach (id => promises .push (destroy (` ${ this .deleteResourceUri || this .resourceUri } /${ id} ` )));
244+ ids .forEach (id => promises .push (axios . delete (` ${ this .deleteResourceUri || this .resourceUri } /${ id} ` )));
252245 Promise .all (promises).then (() => resolve ());
253246 });
254247 },
0 commit comments