aboutsummaryrefslogtreecommitdiff
path: root/populateDb.ts
diff options
context:
space:
mode:
Diffstat (limited to 'populateDb.ts')
-rw-r--r--populateDb.ts42
1 files changed, 19 insertions, 23 deletions
diff --git a/populateDb.ts b/populateDb.ts
index 1442350..6f5beaf 100644
--- a/populateDb.ts
+++ b/populateDb.ts
@@ -1,28 +1,24 @@
import mongoose from 'mongoose';
+import Promise from 'bluebird';
import app from './app';
mongoose.connect('mongodb://localhost:27017/which', { useNewUrlParser: true });
-import UserModel from './models/users/user.model';
-(async () => {
- const users = [
- { name: "Emma" },
- { name: "Elise" },
- { name: "Jack" },
- { name: "Oliver" },
- { name: "Jamie" },
- { name: "Aidan" },
- { name: "Jordan" },
- { name: "Erin" },
- { name: "William" },
- { name: "Ethan" },
- ];
- try {
- for (const user of users) {
- await UserModel.create(user);
- }
- } catch (e) {
- console.error(e);
- }
- mongoose.disconnect();
-})(); \ No newline at end of file
+const users = [
+ { name: "Emma" },
+ { name: "Elise" },
+ { name: "Jack" },
+ { name: "Oliver" },
+ { name: "Jamie" },
+ { name: "Aidan" },
+ { name: "Jordan" },
+ { name: "Erin" },
+ { name: "William" },
+ { name: "Ethan" },
+];
+
+Promise.map(users, async user => {
+ return await app.service('users').create(user);
+}).catch(e => console.error(e))
+ .finally(() => mongoose.disconnect());
+