fake.ts 1.63 KB
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");
  }
}