aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-11 20:03:35 +0300
committereug-vs <eug-vs@keemail.me>2020-06-11 20:03:35 +0300
commit72a89f5eff0a7b93d5cc5cf81255b9a1efcf20f1 (patch)
tree717f243eae5f2194b221074adccf9b725b3e88a3
parent1cecd0202f6f891d5f76132ee17353c6e35d91a8 (diff)
downloadwhich-api-72a89f5eff0a7b93d5cc5cf81255b9a1efcf20f1.tar.gz
refactor: improve script
-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());
+