fake.ts
1.63 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Connection } from "typeorm";
import User from "entity/User";
import Org from "entity/Org";
import Model from "entity/Model";
export default async function fake(connection: Connection) {
const userRepo = connection.getRepository(User);
const result = await userRepo.find();
console.log(result);
if (result.length > 0) {
console.log("NOT FIRST.. END FAKE");
return;
}
try {
console.log("FIRST.. FAKE START");
let user = new User();
user.email = "db@khu.ac.kr";
user.password = "db";
await userRepo.save(user);
console.log("USER DONE");
let modelA = new Model();
modelA.name = "F15";
let modelB = new Model();
modelB.name = "F20";
let modelC = new Model();
modelC.name = "Raptor";
let modelD = new Model();
modelD.name = "F22";
let modelE = new Model();
modelE.name = "Valkyrie";
let modelF = new Model();
modelF.name = "Battlecruiser";
console.log("MODEL READY");
await connection
.createQueryBuilder()
.insert()
.into(Model)
.values([modelA, modelB, modelC, modelD, modelE, modelF])
.execute();
console.log("MODEL DONE");
let OrgA = new Org();
OrgA.name = "서울";
let OrgB = new Org();
OrgB.name = "수원";
let OrgC = new Org();
OrgC.name = "부산";
let OrgD = new Org();
OrgD.name = "춘천";
console.log("ORG READY");
await connection
.createQueryBuilder()
.insert()
.into(Org)
.values([OrgA, OrgB, OrgC, OrgD])
.execute();
console.log("ORG DONE");
console.log("FAKE OVER");
} catch (e) {
console.log(e, "FAKE ERROR");
}
}