11import axios from "axios" ;
22
33export default {
4- async getDirectionsFromApi ( ) {
5- return await axios . request ( {
4+ async getDirectionsFromApi ( ) {
5+ return await axios . request ( {
66 url : 'v1/direction' ,
77 method : 'GET'
88 } ) . then ( resp => {
99 return resp . data . directions
1010 } ) . catch ( err => {
11- return err
11+ return err
1212 } )
1313 } ,
1414 async getInstitutesFromApi ( ) {
@@ -31,17 +31,17 @@ export default {
3131 return err
3232 } )
3333 } ,
34- async getSectorsFromApi ( institute = { id :'' } , direction = { id :'' } , profile = { id :'' } ) {
35- return await axios . request ( {
36- url : 'v1/sector' ,
37- method : 'GET' ,
38- params : { institute : institute . id , direction : direction . id , profile : profile . id }
39- } ) . then ( resp => {
40- console . log ( 'getSectorsFromApi ' , institute )
41- return resp . data
42- } ) . catch ( err => {
43- return err
44- } )
34+ async getSectorsFromApi ( institute = { id : '' } , direction = { id : '' } , profile = { id : '' } ) {
35+ return await axios . request ( {
36+ url : 'v1/sector' ,
37+ method : 'GET' ,
38+ params : { institute : institute . id , direction : direction . id , profile : profile . id }
39+ } ) . then ( resp => {
40+ console . log ( 'getSectorsFromApi ' , institute )
41+ return resp . data
42+ } ) . catch ( err => {
43+ return err
44+ } )
4545 } ,
4646 async postSectorsToApi ( data ) {
4747 return await axios . request ( {
@@ -53,24 +53,28 @@ export default {
5353 alert ( 'Успешно создано!' )
5454 return resp . data
5555 } ) . catch ( err => {
56- if ( err . response . status === 404 ) {
56+ if ( err . response . status === 404 ) {
5757 console . log ( '404' , err . response . status , data . sectors . coords [ 0 ] )
58- this . postNewSectorToApi ( data . sectors . coords [ 0 ] , data )
59- }
60- else {
58+ this . postNewSectorToApi ( data . sectors . coords , data )
59+ } else {
6160 alert ( 'Не получилось, проверьте правильность ввденных данных' )
6261 }
6362 console . log ( err )
6463 return err
6564 } )
6665 } ,
6766 async postNewSectorToApi ( idSectors , dataLastRequest ) {
67+ let data = [ ]
68+ idSectors . forEach ( elem => {
69+ data . push ( {
70+ "coords" : elem ,
71+ "description" : "empty"
72+ } )
73+ } )
6874 return await axios . request ( {
69- url : 'v1/sector ' ,
75+ url : 'v1/sectors ' ,
7076 method : 'POST' ,
71- data : {
72- "coords" : idSectors
73- }
77+ data : data
7478 } ) . then ( resp => {
7579 console . log ( 'postNewSectorToApi ' , resp )
7680 this . postSectorsToApi ( dataLastRequest )
0 commit comments