DELETE https://localhost:44382/Admin/stocks 404 spread.js:25 - asp.net

Im stuck, i tried everything, cant find it please help me...
Console: DELETE https://localhost:44382/Admin/stocks 404 spread.js:25
code:
deleteStock(id, index) {
this.loading = true;
axios.delete('/Admin/stocks' + id)
.then(res => {
console.log(res);
this.selectedProduct.stock.splice(index, 1);
})
.catch(err => {
console.log(err);
})
.then(() => {
this.loading = false;
});
},

Related

Ionic Cordova Firebase Facebook login error: "Sorry, something went wrong. We are working on it and we'll get it fixed as soon as we can"

I'm trying to login users with Facebook and Firebase, I have followed the documentation and some tutorials but I cannot make it work. I'm having this:
enter image description here
Plugin version:
"cordova-plugin-facebook4": "^6.4.0",
Also:
"cordova-plugin-facebook4": {
"APP_ID": "47**********",
"APP_NAME": "Mimas"
},**
My code:
public authWithFacebook(): Promise<any> {
return new Promise(async (resolve, reject) => {
if (this.platform.is('cordova')) {
await this.facebook.login(['public_profile']).then((res) => {
console.log(res);
const credential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
this.afAuth.auth.signInWithCredential(credential).then(response => {
console.log(response);
resolve(response);
}).catch(err => {
console.log(err);
reject(this.translate.get(err.code));
});
}).catch(err => {
console.log("ERROR =========>");
console.log(err);
reject();
});
} else {
console.log("ELSEEEEEE =========>");
const fbprovider = new firebase.auth.FacebookAuthProvider();
this.afAuth.auth.signInWithPopup(fbprovider).then(res => {
resolve(res);
}).catch((e) => {
reject(e);
});
}
});
}

Angular filtering problem when using pipe and map response

shop.service.ts code
getProducts(brandId?: number, typeId?: number) {
let params = new HttpParams();
if (brandId){
params = params.append('brandId', brandId.toString());
}
if (typeId){
params = params.append('typeId', typeId.toString());
}
return this.http.get<IPagination>(this.baseUrl + 'products', {observe: 'response', params})
.pipe(
map(response => {
return response.body;
})
);
}
and shop.component.ts code here
getProducts(){
this.shopService.getProducts(this.brandIdSelected, this.typeIdSelected).subscribe(response => {
this.products = response.data;
}, error => {
console.log(error);
});
}
Please see those code and give me a suggestion Why response.data is showing error in shop.component.ts?
Note: Object is possiblly 'null' : ts(2531) error message showing.
It's because http.get() might return no value.
this.http.get<IPagination>(this.baseUrl + 'products', {observe: 'response', params}).pipe(map(response => {
// response can be null or undefined and so can response.body
return response.body;
})
);
But here you do not take this possibility into account and directly try to access response.data.
getProducts(){
this.shopService.getProducts(this.brandIdSelected, this.typeIdSelected).subscribe(response => {
this.products = response.data;
}, error => {
console.log(error);
});
Do it with an if-condition. Then the compiler won't throw this error.
getProducts(){
this.shopService.getProducts(this.brandIdSelected, this.typeIdSelected).subscribe(response => {
// only if response is not null or undefined, access the data-field
if (response) {
this.products = response.data;
}
}, error => {
console.log(error);
});

Firebase get request querying multiple tables

I'm trying to send get request to get the information of a row and that of its comments and options (rows, comments, options are all different tables). Currently, the request returns the row and comment info, but an empty array for the options, like so:
{
"categoryId": "Category1",
"dataType": "Text",
"approveCount": 0,
"createdAt": "10:00",
"body": "testneww",
"disapproveCount": 0,
"index": 1,
"visit": "Both",
"rowId": "ID",
"comments": [
{
"rowId": "ID",
"createdAt": "2021-02-28T21:32:52.841Z",
"body": "test comment"
}
],
"options": []
}
code:
exports.getOneRow = (req, res) => {
let rowData = {};
db.doc(`/rows/${req.params.rowId}`)
.get()
.then((doc) => {
if (!doc.exists) {
return res.status(404).json({ error: 'Row not found' });
}
rowData = doc.data();
rowData.rowId = doc.id;
return db
.collection('comments')
.orderBy('createdAt', 'desc')
.where('rowId', '==', req.params.rowId)
.get();
})
.then((data) => {
rowData.comments = [];
data.forEach((doc) => {
rowData.comments.push(doc.data());
})
return db
.collection('options')
.orderBy('index', 'asc')
.where('rowId', '==', req.params.rowId)
.get();
})
.then((newData)=>{
rowData.options = [];
newData.forEach((newDoc) => {
rowData.options.push(newDoc.data());
})
return res.json(rowData);
})
.catch((err) => {
console.error(err);
res.status(500).json({ error: err.code });
});
};
I presume I'm making a silly mistake somwhere, or is it not possible to do a request like this? Any help appreciated!
The following code worked, I cant see any differences besides adding the parameters individually in 'rowData.options.push' near the end, however ive been staring at the same code for quite a while so please do let me know if im missing something else.
exports.getOneRow = (req, res) => {
let rowData = {};
db.doc(`/rows/${req.params.rowId}`)
.get()
.then((doc) => {
if (doc.exists) {
rowData = doc.data();
rowData.rowId = doc.id
return db
.collection("comments")
.where("rowId", "==", req.params.rowId)
.get();
} else{
return res.status(500).json({ error: err.code });
}
})
.then((data) => {
rowData.comments = [];
data.forEach((doc) => {
rowData.comments.push(doc.data());
});
return db
.collection("options")
.where("rowId", "==", req.params.rowId)
.orderBy("index", "asc")
.get();
})
.then((data) => {
rowData.options = [];
data.forEach((doc) => {
rowData.options.push({
index: doc.data().index,
body: doc.data().body,
rowId: doc.data().rowId,
});
});
return res.json(rowData);
})
.catch((err) => {
console.error(err);
return res.status(500).json({ error: err.code });
});
};

Firestore vuejs chained calls stop

I've been studying the tutorial on https://savvyapps.com/blog/definitive-guide-building-web-app-vuejs-firebase. The following piece of code was not properly working for me.
signup() {
fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password).then(user => {
this.$store.commit('setCurrentUser', user)
// create user obj
fb.usersCollection.doc(user.uid).set({
name: this.signupForm.name,
title: this.signupForm.title
}).then(() => {
this.$store.dispatch('fetchUserProfile')
this.$router.push('/dashboard')
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err)
})
}
Could anyone help me?
P.S: After lots of research, I've stumbled upon that by this way I got the document created but the code inside then is not working yet. This change was based on Doug Stevenson's video on youtube about promises.
const promise = fb.usersCollection.doc(user.user.uid).set({
name: this.signupForm.name,
title: this.signupForm.title
})
return promise.then(() => {
console.log('set ok')
this.$store.dispatch('fetchUserProfile')
this.performingRequest = false
this.$router.push('/dashboard')
}).catch(err => {
this.performingRequest = false
console.log(err)
this.errorMsg = err.message
})
P.S 2: The line of code below helps to get the document created:
firebase.firestore().settings({ experimentalForceLongPolling: true })
Tylerhan has answered the question on github. Here is the solution:
async signup () {
this.performingRequest = true
await fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password).then(user => {
this.$store.commit('setCurrentUser', user.user)
})
const user = this.$store.getters.getCurrentUser
const userProfile = {
name: this.signupForm.name,
title: this.signupForm.title
}
fb.usersCollection.doc(user.uid).set(userProfile).then(() => {
this.$store.dispatch('fetchUserProfile')
this.performingRequest = false
this.$router.push('/dashboard')
}).catch(err => {
this.performingRequest = false
console.log(err)
this.errorMsg = err.message
})
}

Add Firebase image URL to my collection

I have the following method I'm accessing when my VueJS component is loading:
getServices () {
fb.servicesCollection.get().then(querySnapshot => {
this.serviceList = []
querySnapshot.forEach(doc => {
const { name, icon } = doc.data()
fb.storage.ref().child(icon).getDownloadURL().then(function (url) {
console.log(url)
})
this.serviceList.push({id: doc.id, name: name, icon: 'iconURL'})
})
this.isLoading = false
}).catch(error => {
console.log(error)
})
}
What I want to achieve is to get the url to replace the current 'iconURL' string. Didn't find any method to do that in the last couple of hours. Please help!
The following should do the trick. (However note that I could no test it, so it may need a bit of fine tuning... You can report how it works in the comments and we correct it if necessary)
Since you want to execute several getDownloadURL() asynchronous calls to Firebase Storage in parallel, you have to use Promise.all(), since getDownloadURL() returns a promise, see the doc.
getServices () {
let namesArray = []
let docIdArray = []
fb.servicesCollection.get().then(querySnapshot => {
this.serviceList = []
let promises = []
querySnapshot.forEach(doc => {
const icon = doc.data().icon;
promises.push(fb.storage.ref().child(icon).getDownloadURL())
namesArray.push(doc.data().name)
docIdArray.push(doc.id)
})
return Promise.all(promises)
})
.then(results => {
results.forEach((value, index) => {
this.serviceList.push({id: docIdArray[index], name: namesArray[index], icon: value})
})
})
}).catch(error => {
console.log(error)
})
}
This is how I got it in the end...
getServices () {
fb.servicesCollection.get().then(querySnapshot => {
this.serviceList = []
querySnapshot.forEach(doc => {
const { name, icon } = doc.data()
fb.storage.ref(icon).getDownloadURL().then(url => {
this.serviceList.push({id: doc.id, name: name, icon: url})
})
})
this.isLoading = false
}).catch(error => {
console.log(error)
})
}
Thank you for all your efforts to help me!!! Highly appreciate it!

Resources