Update database/database.js
Browse files- database/database.js +9 -10
database/database.js
CHANGED
@@ -4,9 +4,8 @@ import * as config from '../config.js';
|
|
4 |
const client = new MongoClient(config.dbUri);
|
5 |
|
6 |
class Database {
|
7 |
-
constructor(dbname
|
8 |
this.dbname = dbname;
|
9 |
-
this.collectionName = collectionName;
|
10 |
}
|
11 |
|
12 |
async connect() {
|
@@ -20,10 +19,10 @@ class Database {
|
|
20 |
}
|
21 |
}
|
22 |
|
23 |
-
collection() {
|
24 |
try {
|
25 |
const db = client.db(this.dbname);
|
26 |
-
return db.collection(
|
27 |
} catch (error) {
|
28 |
console.error("Error accessing collection:", error.message);
|
29 |
}
|
@@ -40,9 +39,9 @@ class Database {
|
|
40 |
|
41 |
async IPAddressAndUpdate(ip) {
|
42 |
try {
|
43 |
-
const collection = this.collection();
|
44 |
-
const filter = { ip: ip };
|
45 |
-
const update = { $set: { ip: ip } };
|
46 |
|
47 |
const result = await collection.updateOne(filter, update, { upsert: true });
|
48 |
|
@@ -58,7 +57,7 @@ class Database {
|
|
58 |
|
59 |
async UnblockedIp(ip) {
|
60 |
try {
|
61 |
-
const collection = this.collection();
|
62 |
const filter = { ip: ip };
|
63 |
const update = { $set: { blocked: false } };
|
64 |
|
@@ -76,7 +75,7 @@ class Database {
|
|
76 |
|
77 |
async AddIpisBlocked(ip) {
|
78 |
try {
|
79 |
-
const collection = this.collection();
|
80 |
const filter = { ip: ip };
|
81 |
const update = { $set: { blocked: true } };
|
82 |
|
@@ -94,7 +93,7 @@ class Database {
|
|
94 |
|
95 |
async CheckIsBlocked(ip) {
|
96 |
try {
|
97 |
-
const collection = this.collection();
|
98 |
const filter = { ip: ip };
|
99 |
const update = { $set: { blocked: true } };
|
100 |
|
|
|
4 |
const client = new MongoClient(config.dbUri);
|
5 |
|
6 |
class Database {
|
7 |
+
constructor(dbname) {
|
8 |
this.dbname = dbname;
|
|
|
9 |
}
|
10 |
|
11 |
async connect() {
|
|
|
19 |
}
|
20 |
}
|
21 |
|
22 |
+
collection(collectionName) {
|
23 |
try {
|
24 |
const db = client.db(this.dbname);
|
25 |
+
return db.collection(collectionName);
|
26 |
} catch (error) {
|
27 |
console.error("Error accessing collection:", error.message);
|
28 |
}
|
|
|
39 |
|
40 |
async IPAddressAndUpdate(ip) {
|
41 |
try {
|
42 |
+
const collection = this.collection("FastJsAPI");
|
43 |
+
const filter = { ip: ip };
|
44 |
+
const update = { $set: { ip: ip } };
|
45 |
|
46 |
const result = await collection.updateOne(filter, update, { upsert: true });
|
47 |
|
|
|
57 |
|
58 |
async UnblockedIp(ip) {
|
59 |
try {
|
60 |
+
const collection = this.collection("FastJsAPI");
|
61 |
const filter = { ip: ip };
|
62 |
const update = { $set: { blocked: false } };
|
63 |
|
|
|
75 |
|
76 |
async AddIpisBlocked(ip) {
|
77 |
try {
|
78 |
+
const collection = this.collection("FastJsAPI");
|
79 |
const filter = { ip: ip };
|
80 |
const update = { $set: { blocked: true } };
|
81 |
|
|
|
93 |
|
94 |
async CheckIsBlocked(ip) {
|
95 |
try {
|
96 |
+
const collection = this.collection("FastJsAPI");
|
97 |
const filter = { ip: ip };
|
98 |
const update = { $set: { blocked: true } };
|
99 |
|