codebase-models 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +14 -8
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -45,7 +45,7 @@ import Trigger from "./src/models/Trigger";
|
|
|
45
45
|
import ClientScript from "./src/models/ClientScript";
|
|
46
46
|
import ClientExperiment from "./src/models/ClientExperiment";
|
|
47
47
|
import Audience from "./src/models/Audience";
|
|
48
|
-
import Environment from
|
|
48
|
+
import Environment from "./src/models/Environment";
|
|
49
49
|
|
|
50
50
|
async function seedRoles() {
|
|
51
51
|
const checkRoles = await Role.countDocuments();
|
|
@@ -69,6 +69,7 @@ async function seedRoles() {
|
|
|
69
69
|
]);
|
|
70
70
|
})
|
|
71
71
|
);
|
|
72
|
+
console.log("Roles seeded successfully");
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -77,13 +78,18 @@ export async function connect(
|
|
|
77
78
|
options?: mongoose.ConnectOptions | undefined
|
|
78
79
|
): Promise<typeof mongoose> {
|
|
79
80
|
if (uri) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
if (mongoose.connection.readyState === 1) {
|
|
82
|
+
// Already connected
|
|
83
|
+
console.log("Already connected to the database");
|
|
84
|
+
return mongoose;
|
|
85
|
+
} else {
|
|
86
|
+
console.log("Connecting to the database on URI: ", uri);
|
|
87
|
+
const mongooseConnection = await mongoose.connect(uri, options);
|
|
88
|
+
if (mongooseConnection.connection.readyState === 1) {
|
|
89
|
+
await seedRoles();
|
|
90
|
+
}
|
|
91
|
+
return mongooseConnection;
|
|
85
92
|
}
|
|
86
|
-
return mongooseConnection;
|
|
87
93
|
}
|
|
88
94
|
throw new Error("URI is required to connect to the database");
|
|
89
95
|
}
|
|
@@ -134,5 +140,5 @@ export {
|
|
|
134
140
|
ClientScript,
|
|
135
141
|
ClientExperiment,
|
|
136
142
|
Audience,
|
|
137
|
-
Environment
|
|
143
|
+
Environment,
|
|
138
144
|
};
|