-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_single.js
40 lines (34 loc) · 1.22 KB
/
delete_single.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module.exports = {
deleteSingle: (postID, postTitle, checkBySlug) => {
const Firestore = require('@google-cloud/firestore');
const _ = require('lodash');
const firestore = new Firestore({
projectId: 'livinmalta-affc2',
keyFilename: './configs/livinmalta-affc2-firebase-adminsdk-s7vnu-34464170f6.json',
});
const dupeArray = [];
if(checkBySlug) {
console.log('Found property: ', checkBySlug);
}
// check if title exists
// delete by id
deleteById(postID);
deleteByTitle(postTitle);
function deleteById(postID){
if (postID) {
firestore.doc('scraped_posts/' + postID).delete().then(() => {
console.log('Delete post: ', postID, ' :id: ', postID, ' -DELETED');
});
}
}
function deleteByTitle(postTitle) {
if (postTitle) {
firestore.collection('scraped_posts').where('title', '==', postTitle)
.get()
.then(querySnapshot => {
deleteById( querySnapshot.docs[0].id);
})
}
}
}
}