conflict fix
Showing
| ... | @@ -3,110 +3,122 @@ import { Injectable } from '@angular/core'; | ... | @@ -3,110 +3,122 @@ import { Injectable } from '@angular/core'; |
| import { AngularFirestore } from '@angular/fire/firestore'; | import { AngularFirestore } from '@angular/fire/firestore'; | ||
| import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | ||
| import { ServiceService } from './service.service'; | import { ServiceService } from './service.service'; | ||
| import { AddressService } from './address.service'; | |||
| import * as firebase from 'firebase'; | import * as firebase from 'firebase'; | ||
| import { take } from 'rxjs/operators'; | import { take } from 'rxjs/operators'; | ||
| let CartsService = class CartsService { | let CartsService = class CartsService { | ||
| constructor(afs, router, service) { | constructor(afs, router, service, addressService) { | ||
| this.afs = afs; | this.afs = afs; | ||
| this.router = router; | this.router = router; | ||
| this.service = service; | this.service = service; | ||
| this.addressService = addressService; | |||
| this.carts = []; | this.carts = []; | ||
| this.custId = ''; | this.custId = ''; | ||
| this.cartCenter = ''; | |||
| this.carts = []; | this.carts = []; | ||
| const users = this.service.get('user').then(data => { | const users = this.service.get('user').then(data => { | ||
| if (data) { | if (data) { | ||
| data = JSON.parse(data); | data = JSON.parse(data); | ||
| this.custId = data.uid; | this.custId = data.uid; | ||
| // console.log(this.custId); | console.log(this.custId); | ||
| } | } | ||
| }); | }); | ||
| } | } | ||
| buyNow(product) { | buyNow(product) { | ||
| return tslib_1.__awaiter(this, void 0, void 0, function* () { | return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
| this.prodId = product.prodId; | const promise = new Promise(resolve => { | ||
| const prodRef = firebase | this.prodId = product.prodId; | ||
| .firestore() | const prodRef = firebase | ||
| .collection('products') | .firestore() | ||
| .doc(this.prodId); | .collection('products') | ||
| this.size = this.size === undefined ? product.size[0] : this.size; | .doc(this.prodId); | ||
| this.color = this.color === undefined ? product.color[0] : this.color; | this.size = this.size === undefined ? product.size[0] : this.size; | ||
| this.service.get('cartCenter').then((centerData) => { | this.color = this.color === undefined ? product.color[0] : this.color; | ||
| console.log(centerData); | if (this.cartCenter === '' || (this.cartCenter === product.centerId)) { | ||
| if (centerData === null || (centerData === product.centerId)) { | if (this.cartCenter === '') { | ||
| this.service.set('cartCenter', product.centerId).then(() => { | this.cartCenter = product.centerId; | ||
| const cartRef = this.afs.collection('carts', ref => ref | this.addressService.defaultAddress(this.custId); | ||
| .where('size', '==', this.size) | this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance); | ||
| .where('color', '==', this.color) | } | ||
| .where('custId', '==', this.custId) | const cartRef = this.afs.collection('carts', ref => ref | ||
| .where('product', '==', prodRef)); | .where('size', '==', this.size) | ||
| cartRef | .where('color', '==', this.color) | ||
| .valueChanges() | .where('custId', '==', this.custId) | ||
| .pipe(take(1)) | .where('product', '==', prodRef)); | ||
| .subscribe(value => { | cartRef | ||
| // console.log(value); | .valueChanges() | ||
| if (value.length === 0) { | .pipe(take(1)) | ||
| product.image = | .subscribe(value => { | ||
| product.image === undefined | // console.log(value); | ||
| ? '../assets/[email protected]' | if (value.length === 0) { | ||
| : product.image; | product.image = | ||
| const cart = { | product.image === undefined | ||
| color: this.color, | ? '../assets/[email protected]' | ||
| custId: this.custId, | : product.image; | ||
| shopperId: product.shopperId, | const cart = { | ||
| product: firebase.firestore().doc(`products/${this.prodId}`), | color: this.color, | ||
| image: product.image, | custId: this.custId, | ||
| prodId: product.prodId, | shopperId: product.shopperId, | ||
| price: product.price, | product: firebase.firestore().doc(`products/${this.prodId}`), | ||
| prodName: product.prodName, | image: product.image, | ||
| shopper: product.shopper, | prodId: product.prodId, | ||
| qty: 1, | price: product.price, | ||
| size: this.size | prodName: product.prodName, | ||
| }; | shopper: product.shopper, | ||
| // console.log(cart); | centerId: product.centerId, | ||
| this.afs | qty: 1, | ||
| .collection('carts') | size: this.size | ||
| .add(cart) | }; | ||
| .then(docRef => { | // console.log(cart); | ||
| const neworderId = docRef.id; | this.afs | ||
| this.afs | .collection('carts') | ||
| .collection('carts') | .add(cart) | ||
| .doc(neworderId) | .then(docRef => { | ||
| .update({ cartId: docRef.id }) | const neworderId = docRef.id; | ||
| .then(() => { | |||
| // console.log('Booking Successfully'); | |||
| document.body.scrollTop = document.documentElement.scrollTop = 0; | |||
| }); | |||
| }) | |||
| .catch(error => { | |||
| console.error('Error adding document: ', error); | |||
| }); | |||
| } | |||
| else { | |||
| // console.log(value); | |||
| // alert('Item already added in the cart'); | |||
| const cartId = value[0].cartId; | |||
| // tslint:disable-next-line:radix | |||
| const qty = parseInt(value[0].qty) + 1; | |||
| this.afs | this.afs | ||
| .collection('carts') | .collection('carts') | ||
| .doc(cartId) | .doc(neworderId) | ||
| .update({ qty: `${qty}` }) | .update({ cartId: docRef.id }) | ||
| .then(() => { | .then(() => { | ||
| // console.log('Booking Successfully'); | // console.log('Booking Successfully'); | ||
| document.body.scrollTop = document.documentElement.scrollTop = 0; | document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
| }); | }); | ||
| } | resolve(true); | ||
| }); | }) | ||
| .catch(error => { | |||
| console.error('Error adding document: ', error); | |||
| resolve(false); | |||
| }); | |||
| } | |||
| else { | |||
| // console.log(value); | |||
| // alert('Item already added in the cart'); | |||
| const cartId = value[0].cartId; | |||
| // tslint:disable-next-line:radix | |||
| const qty = parseInt(value[0].qty) + 1; | |||
| this.afs | |||
| .collection('carts') | |||
| .doc(cartId) | |||
| .update({ qty: `${qty}` }) | |||
| .then(() => { | |||
| // console.log('Booking Successfully'); | |||
| document.body.scrollTop = document.documentElement.scrollTop = 0; | |||
| }); | |||
| resolve(true); | |||
| } | |||
| }); | }); | ||
| } | } | ||
| else { | else { | ||
| this.service.showToast('Your cart is not empty', 'top', 'my-error', 2000); | this.service.showToast('Your cart is not empty', 'top', 'my-error', 2000); | ||
| resolve(false); | |||
| } | } | ||
| }); | }); | ||
| return promise; | |||
| }); | }); | ||
| } | } | ||
| cartList() { | cartList(custId) { | ||
| return tslib_1.__awaiter(this, void 0, void 0, function* () { | return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
| this.custId = custId; | |||
| console.log('called'); | console.log('called'); | ||
| const cartRef = this.afs.collection('carts', ref => ref.where('custId', '==', this.custId)); | const cartRef = this.afs.collection('carts', ref => ref.where('custId', '==', this.custId)); | ||
| cartRef.valueChanges().subscribe(value => { | cartRef.valueChanges().subscribe(value => { | ||
| ... | @@ -114,6 +126,11 @@ let CartsService = class CartsService { | ... | @@ -114,6 +126,11 @@ let CartsService = class CartsService { |
| const res = value; | const res = value; | ||
| this.cartTotal = 0; | this.cartTotal = 0; | ||
| if (res.length > 0) { | if (res.length > 0) { | ||
| if (this.cartCenter === '') { | |||
| this.cartCenter = res[0].centerId; | |||
| this.addressService.defaultAddress(this.custId); | |||
| this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance); | |||
| } | |||
| res.forEach(item => { | res.forEach(item => { | ||
| const cartItem = { | const cartItem = { | ||
| cartId: item.cartId, | cartId: item.cartId, | ||
| ... | @@ -144,7 +161,7 @@ let CartsService = class CartsService { | ... | @@ -144,7 +161,7 @@ let CartsService = class CartsService { |
| }); | }); | ||
| } | } | ||
| else { | else { | ||
| this.service.remove('cartCenter'); | this.cartCenter = ''; | ||
| // alert('No Products Found'); | // alert('No Products Found'); | ||
| } | } | ||
| }); | }); | ||
| ... | @@ -200,7 +217,8 @@ CartsService = tslib_1.__decorate([ | ... | @@ -200,7 +217,8 @@ CartsService = tslib_1.__decorate([ |
| }), | }), | ||
| tslib_1.__metadata("design:paramtypes", [AngularFirestore, | tslib_1.__metadata("design:paramtypes", [AngularFirestore, | ||
| Router, | Router, | ||
| ServiceService]) | ServiceService, | ||
| AddressService]) | |||
| ], CartsService); | ], CartsService); | ||
| export { CartsService }; | export { CartsService }; | ||
| //# sourceMappingURL=cart.service.js.map | //# sourceMappingURL=cart.service.js.map | ||
| \ No newline at end of file |
Please
register
or
sign in
to comment