-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanelToMongo.js
78 lines (59 loc) · 2.24 KB
/
PanelToMongo.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
73
74
75
76
77
78
const clientModel = require("./../database/models/clientModel");
const axios = require("axios");
require("dotenv").config()
const fs = require('fs')
const util = require('util');
const database = require("./../database/databaseConnect");
module.exports.getPanelUsers = async function () {
console.log("panelUser2")
try {
let request = await axios.get(process.env.PTERO_URL + "application/users", {
"headers": {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + process.env.PTERO_API_KEY
}
})
request.data.data.map(async user => {
let username = user.attributes.username;
let id = user.attributes.id;
let firstName = user.attributes.first_name;
let lastName = user.attributes.last_name;
let email = user.attributes.email;
if (Number.isInteger(parseInt(username))) {
clientModel.findOne({discordId: username}, async (err, data) => {
if (err) throw err;
if (!data) {
const newClient = new clientModel({
discordId: username,
name: firstName,
surname: lastName,
email: email,
offresCount:0,
});
await newClient.save();
} else {
// console.log("User already in database");
}
})
} else {
let userJson =
`{
"username": "${username}",
"email": "${email}",
"name": "${firstName}",
"surname": "${lastName}",
"id": "${id}"
}`
try {
let log_file = fs.createWriteStream(__dirname + '/NotVerified/' + username + '.json', {flags: 'w'});
log_file.write(userJson);
} catch (e) {
console.log(e)
}
}
})
} catch (e) {
console.log(e.response)
}
}