@@ -63,15 +63,8 @@ export class FoodService {
63
63
else {
64
64
// Загрузка из REST
65
65
this . loadRest ( ) . subscribe (
66
- ( resp : Response ) => {
67
- let respfood = resp . json ( ) [ "food" ]
68
- if ( respfood != null ) {
69
- this . food = respfood ;
70
- } else {
71
- this . food = { } ;
72
- }
73
- respfood != null ? this . food = respfood : this . food = { } ;
74
-
66
+ ( food ) => {
67
+ food != null ? this . food = food : this . food = { } ;
75
68
this . saveFood ( ) ;
76
69
this . foodsChanged . emit ( ) ;
77
70
} ,
@@ -89,22 +82,36 @@ export class FoodService {
89
82
90
83
91
84
private getUrl ( ) : string {
92
- return `https ://pushreceiver-26e46.firebaseio.com/food.json?auth= ${ this . tk } `
85
+ return `http ://localhost:8000/api/v1/menu/ `
93
86
}
94
87
95
88
loadRest ( ) {
96
- return this . http . get ( this . getUrl ( ) ) ;
89
+ return this . http . get ( this . getUrl ( ) )
90
+ . map ( ( response :Response ) => {
91
+ let f = { }
92
+ let weeks = response . json ( ) [ "results" ]
93
+ for ( let i = 0 ; i < weeks . length ; i ++ ) {
94
+ let week = weeks [ i ] ;
95
+ let num = week [ 'num' ] ;
96
+ delete week [ 'num' ] ;
97
+ f [ num ] = week ;
98
+ }
99
+ return f ;
100
+ } ) ;
97
101
}
98
102
99
103
saveRest ( ) {
100
- let temp = { }
101
- temp [ "food" ] = this . food ;
102
-
103
- this . http . put ( this . getUrl ( ) , temp ) . subscribe (
104
- ( resp : Response ) => {
105
- console . log ( resp . json ( ) ) ;
104
+ for ( var week in this . food ) {
105
+ if ( this . food . hasOwnProperty ( week ) ) {
106
+ var menu = this . food [ week ] ;
107
+ menu [ 'num' ] = week ;
108
+ console . log ( JSON . stringify ( menu ) ) ;
109
+ this . http . post ( this . getUrl ( ) , menu ) . subscribe (
110
+ ( response :Response ) => { console . log ( response ) } ,
111
+ ( error ) => { console . log ( error ) } ,
112
+ )
106
113
}
107
- )
114
+ }
108
115
}
109
116
getFoodForDay ( code : string ) {
110
117
let food = this . food [ this . weekNum ] [ code ] ;
0 commit comments