-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
51 lines (43 loc) · 1.46 KB
/
seed.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
49
50
require('dotenv').config();
const database = require('./database');
async function seedAdmin(db) {
let Admin = require('./models').Admin;
let repo = Admin.Repository;
let admin = await repo.create('admin', 'admin');
let result = await db.collection('admin').createIndex({"username": 1}, {unique: true});
admin = await repo.fetchOne('admin');
return {
admin, result
};
}
async function indexTenant(db) {
return await db.collection('tenant').createIndex({"name": 1}, {unique: true});
}
async function indexUser(db) {
return await db.collection('user').createIndex({"id": 1}, {unique: true});
}
async function indexItem(db) {
return await db.collection('item').createIndex({"name": 1, "tenant": 1}, {unique: true});
}
async function createDocument(db) {
await db.createCollection('admin');
await db.createCollection('user');
await db.createCollection('tenant');
await db.createCollection('item');
await db.createCollection('point_transaction');
await db.createCollection('item_transaction');
return true;
}
try {
database.initialize().then(db => {
let dbTest = database.get
createDocument(db).then(r => console.log(r));
seedAdmin(db).then(r => console.log(r));
indexTenant(db).then((r) => console.log(r));
indexItem(db).then(r => console.log(r));
indexUser(db).then(r => console.log(r));
});
} catch (e) {
console.log(e.message);
process.exit(1);
}