サンプル3(DELETEサンプル)
概要
Firebase Functionsのコード
機能
コード例
解説
アプリ側のコード
機能
コード例
解説
最終更新
最終更新
const delete_data = functions.https.onCall(async (data, context) => {
const body = data.body;
const id = body.id; // 削除するID
return admin.firestore().collection('Item').doc(id).delete()
.then(_ => {
return { message: `Document ${id} successfully deleted` };
})
.catch(error => {
throw new functions.https.HttpsError('internal', `Error deleting document: ${error}`);
});
}; const deleteId = document.querySelector('#deleteId').value;
log(`${deleteId}`);
const delete_data = httpsCallable(functions, 'delete_data');
delete_data({
'body' : {
'id': deleteId
}
}).then((result) => {
log(result.data);
}).catch((error) => {
log(error);
});
});