@@ -5,11 +5,11 @@ import firebase = require('nativescript-plugin-firebase');
55import { Cost } from '../common/protocol' ;
66import { Config } from "../common/config" ;
77import { Utils } from "../common/utils" ;
8- import { Observable } from "tns-core-modules/ui/editable-text-base/editable-text-base" ;
98
109@Injectable ( )
1110export class CostService {
1211 private _costs : ObservableArray < any > = new ObservableArray ( ) ;
12+ private userid = Config . getUserToken ( ) ;
1313 private listeners ;
1414
1515 get costs ( ) : ObservableArray < any > {
@@ -21,10 +21,9 @@ export class CostService {
2121 return new Promise ( function ( success , error ) {
2222 firebase . addValueEventListener (
2323 ( result ) => {
24- console . log ( 'objectToArray: ' , JSON . stringify ( result ) ) ;
2524 that . _costs = new ObservableArray ( that . objectToArray ( result . value ) ) ;
2625 return success ( ) ;
27- } , `/${ Config . getUserToken ( ) } /costs` ) . then (
26+ } , `/${ this . userid } /costs` ) . then (
2827 listenerWrapper => that . listeners = listenerWrapper . listeners
2928 ) ;
3029 } . bind ( this ) ) ;
@@ -41,21 +40,18 @@ export class CostService {
4140 ranges : [
4241 {
4342 type : firebase . QueryRangeType . START_AT ,
44- value : Utils . dateToYMD ( new Date ( dateRange . startDate ) )
43+ value : ( new Date ( dateRange . startDate ) ) . toISOString ( )
4544 } ,
4645 {
4746 type : firebase . QueryRangeType . END_AT ,
48- value : Utils . dateToYMD ( new Date ( dateRange . endDate ) )
47+ value : Utils . increaseDateByOneDay ( dateRange . endDate )
4948 }
5049 ]
5150 } ;
5251
53- console . log ( JSON . stringify ( parameters ) ) ;
54-
5552 return new Promise ( function ( success , error ) {
5653 firebase . query (
5754 result => {
58- console . log ( 'objectToArray: ' , JSON . stringify ( result ) ) ;
5955 that . _costs = new ObservableArray ( that . objectToArray ( result . value ) ) ;
6056 return success ( ) ;
6157 } ,
@@ -70,18 +66,18 @@ export class CostService {
7066 }
7167
7268 addCost ( newCost : Cost ) {
73- firebase . push ( `/${ Config . getUserToken ( ) } /costs` , newCost ) . then ( result => {
69+ firebase . push ( `/${ this . userid } /costs` , newCost ) . then ( result => {
7470 newCost . id = result . key ;
7571 this . _costs . unshift ( newCost ) ;
7672 } ) ;
7773 }
7874
7975 updateCost ( costForUpdate : Cost ) {
80- return firebase . update ( `/${ Config . getUserToken ( ) } /costs/${ costForUpdate . id } ` , costForUpdate ) ;
76+ return firebase . update ( `/${ this . userid } /costs/${ costForUpdate . id } ` , costForUpdate ) ;
8177 }
8278
8379 deleteCost ( costForDelete : Cost ) {
84- firebase . remove ( `/${ Config . getUserToken ( ) } /costs/${ costForDelete . id } ` ) . then ( result => {
80+ firebase . remove ( `/${ this . userid } /costs/${ costForDelete . id } ` ) . then ( result => {
8581 const index = this . _costs . indexOf ( costForDelete ) ;
8682 this . _costs . splice ( index , 1 ) ;
8783 alert ( costForDelete . quantity + " removed!" ) ;
@@ -91,7 +87,7 @@ export class CostService {
9187 removeListeners ( ) {
9288 firebase . removeEventListeners (
9389 this . listeners ,
94- `/${ Config . getUserToken ( ) } /costs`
90+ `/${ this . userid } /costs`
9591 ) ;
9692 }
9793
0 commit comments