-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremove-user-with-email.js
72 lines (55 loc) · 2.6 KB
/
remove-user-with-email.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const readlineSync = require('readline-sync');
exports.removeUserWithEmail = async (container) => {
const email = readlineSync.question('Input email:');
console.log(email)
const user = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'user' and c['value']['profile']['email'] = '" + email + "'")
.fetchAll();
const peerConneId = user.resources[0].value.peer_conne_id
// deleted point-status
const pointStatus = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'point-status' and c['value']['peer_conne_id'] = '" + peerConneId + "'")
.fetchAll();
for (const resource of pointStatus.resources) {
await container.item(resource.id, resource.partitionKey).delete();
}
// deleted point-history
const pointHistorys = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'point-history' and c['value']['metadata']['peer_conne_id'] = '" + peerConneId + "'")
.fetchAll();
for (const resource of pointHistorys.resources) {
await container.item(resource.id, resource.partitionKey).delete();
}
console.log('deleted point history done')
// deleted lottery-application
const lotteryApplications = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'lottery-application' and c['value']['peer_conne_id'] = '" + peerConneId + "'")
.fetchAll();
for (const resource of lotteryApplications.resources) {
await container.item(resource.id, resource.partitionKey).delete();
}
console.log('deleted lottery application done')
// deleted redirect-log
const redirectLogs = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'redirect-log' and c['value']['peer_conne_id'] = '" + peerConneId + "'")
.fetchAll();
for (const resource of redirectLogs.resources) {
await container.item(resource.id, resource.partitionKey).delete();
}
console.log('deleted redirect log done')
// deleted checkin-log
const checkinLogs = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'checkin-log' and c['value']['peer_conne_id'] = '" + peerConneId + "'")
.fetchAll();
for (const resource of checkinLogs.resources) {
await container.item(resource.id, resource.partitionKey).delete();
}
console.log('deleted checkin log done')
// deletd user
const users = await container.items
.query("SELECT * FROM c where c['value']['type'] = 'user' and c['value']['peer_conne_id'] = '" + peerConneId + "'")
.fetchAll();
for (const resource of users.resources) {
await container.item(resource.id, resource.partitionKey).delete();
}
}