-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathInitData.ts
50 lines (44 loc) · 1.19 KB
/
InitData.ts
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
export {};
import { User, UserNote } from '../../api/models';
const USER_1 = {
email: '[email protected]',
role: 'admin',
password: 'user111'
};
const ADMIN_USER_1 = {
email: '[email protected]',
role: 'admin',
password: '1admin1'
};
const ADMIN_USER_2 = {
email: '[email protected]',
role: 'admin',
password: '2admin2'
};
async function setup() {
const createUserNotes = async (user: any, num: number, text: string) => {
for (let i = 0; i < num; i += 1) {
const note = new UserNote({ user, note: `${text} ${i}` });
await note.save();
}
};
const user1 = new User(USER_1);
await user1.save();
await createUserNotes(user1, 100, 'user1 note');
const adminUser1 = new User(ADMIN_USER_1);
await adminUser1.save();
await createUserNotes(adminUser1, 20, 'admin1 note');
const adminUser2 = new User(ADMIN_USER_2);
await adminUser2.save();
await createUserNotes(adminUser2, 20, 'admin2 note');
}
async function checkNewDB() {
const user1 = await User.findOne({ email: USER_1.email });
if (!user1) {
console.log('- New DB detected ===> Initializing Dev Data...');
await setup();
} else {
console.log('- Skip InitData');
}
}
checkNewDB();