Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Created March 17, 2017 17:24
Show Gist options
  • Save annibuliful/a21cb8189910eb206ebf5e24e3dfcc89 to your computer and use it in GitHub Desktop.
Save annibuliful/a21cb8189910eb206ebf5e24e3dfcc89 to your computer and use it in GitHub Desktop.
/*use this function*/
buy() {
let UserId = 'test';
this.Queue = this.list.buy(this.UserProduct);
this.Queue.subscribe(data=> {
console.log(data.length);
if (data.length == 0 ){
this.list.FirstOrder(UserId,this.UserProduct);
}else if(data.length >= 1){
console.log(data.length)
this.list.NextOrder(data.length,UserId,this.UserProduct);
}
});
}
/*function when lenght = 0*/
FirstOrder(UserId: string, ProductId: any[]) {
let add = this.af.database.list(`Order`);
let i = 1;
for (let Id of ProductId) {
add.push({
Queue: i,
UserId: UserId,
ProductId: Id.ProductId,
MerchantId: ProductId[0].MerchantId
}
);
i += 1;
}
}
/*function when length != 0 */
NextOrder(Queue: number, UserId: string, ProductId: any[]) {
let add = this.af.database.list(`Order`);
let i = Queue + 1;
for (let Id of ProductId) {
add.push({
Queue: i,
UserId: UserId,
ProductId: Id.ProductId,
MerchantId: ProductId[0].MerchantId
}
);
i += 1;
}
ProductId = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment