Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. addProduct () {
  2.  
  3.   if (this.productName === '' || this.category === '' || this.price === 0 || this.contactInformation === '' || this.productDetails === '' || this.files.length === 0) {
  4.     this.$q.notify({
  5.       icon: 'close',
  6.       message: 'Fields can not be empty.',
  7.       timeout: 800,
  8.       color: 'negative',
  9.       textColor: 'white',
  10.       position: 'bottom-left'
  11.     });
  12.   } else {
  13.     this.$q.dialog({
  14.       title: 'Confirm',
  15.       message: 'Are you sure you want to continue?',
  16.       ok: {
  17.         color: 'brown'
  18.       },
  19.       cancel: {
  20.         color: 'brown',
  21.         flat: true
  22.       },
  23.       persistent: true
  24.     })
  25.     .onOk(async () => {
  26.  
  27.       const docRef = await this.firebase.firestore().collection('products').add({
  28.         productName: this.productName,
  29.         category: this.category,
  30.         price: this.price,
  31.         contactInformation: this.contactInformation,
  32.         productDetails: this.productDetails,
  33.         displayName: this.user.displayName,
  34.         phoneNumber: this.user.phoneNumber,
  35.         uid: this.user.uid,
  36.         createdAt: Date.now()
  37.       });
  38.  
  39.       const images = [];
  40.       for (const file of files) {
  41.         const storageRef = this.firebase.storage().ref('products/' + this.user.uid + '/' + docRef.id + '/' + file.name);
  42.         const snapshot = await storageRef.put(file);
  43.         const downloadURL = await snapshot.ref.getDownloadURL();
  44.         images.push(downloadURL);
  45.       }
  46.  
  47.       const data = await this.firebase.firestore().collection('products').doc(docRef.id).update({
  48.         images: images
  49.       });
  50.  
  51.       this.$refs.uploader.$data.files = [];
  52.       this.productName = ''
  53.       this.category = ''
  54.       this.price = 0
  55.       this.contactInformation = ''
  56.       this.productDetails = ''
  57.       this.$q.notify({
  58.         icon: 'check',
  59.         message: 'You have successfully added.',
  60.         timeout: 800,
  61.         color: 'brown',
  62.         textColor: 'white',
  63.         position: 'bottom-left'
  64.       });
  65.  
  66.     });
  67.   }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement