-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (41 loc) · 1.07 KB
/
index.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
const mongoose = require("mongoose");
const { DenyListDAO } = require("./deny_list/dao");
const { PostDAO } = require("./post/dao");
const { ManifestationDAO } = require("./manifestation/dao");
const { UserDAO } = require("./user/dao");
const factories = require("./factories");
async function init(dbUri) {
console.log(`Connecting...`);
await mongoose.connect(dbUri, {
useNewUrlParser: true,
useCreateIndex: true,
autoIndex: process.env.NODE_ENV === "development",
useUnifiedTopology: true,
useFindAndModify: false,
});
mongoose.connection
.once("open", () => console.log("Connected!"))
.on("error", (error) => {
console.error(error);
});
}
async function close() {
await mongoose.connection.dropDatabase();
await mongoose.connection.close();
}
async function clear() {
const collections = Object.values(mongoose.connection.collections);
for (const collection of collections) {
await collection.deleteMany();
}
}
module.exports = {
DenyListDAO,
PostDAO,
UserDAO,
ManifestationDAO,
init,
close,
clear,
factories,
};