All files / src App.ts

0% Statements 0/33
0% Branches 0/3
0% Functions 0/4
0% Lines 0/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                                                     
import { CommonEnv, Env } from "./Env";
import { PrismaClient } from "@prisma/client";
import { FetchApplication, Params } from "./application/FetchApplication";
import { createLogger } from "./Logger";
import { findValueStrings } from "lib";
 
// BigIntをログ出力できるようにする
Object.defineProperty(BigInt.prototype, "toJSON", {
  get() {
    "use strict";
    return () => String(this);
  },
});
 
function makeAppParams(args: string[]): Params {
  const appParams = {
    enableElectricity: false,
    enableGas: false,
    enableWater: false,
  };
  for (const enableType of findValueStrings(args, "fetch")) {
    Iif (enableType == "electricity") {
      appParams.enableElectricity = true;
    }
    Iif (enableType == "gas") {
      appParams.enableGas = true;
    }
    Iif (enableType == "water") {
      appParams.enableWater = true;
    }
  }
  return appParams;
}
 
(async () => {
  const commonEnv = new CommonEnv(process.env);
  const logger = createLogger(commonEnv);
 
  try {
    const prisma = new PrismaClient();
    await prisma.$queryRaw`SELECT 1`; // DB接続チェック
 
    const appParams = makeAppParams(process.argv);
 
    const electricityEnv = new Env(process.env, "ELECTRICITY");
    logger.info({ env: electricityEnv }, "loaded electricity env");
 
    const gasEnv = new Env(process.env, "GAS");
    logger.info({ env: gasEnv }, "loaded gas env");
 
    const waterEnv = new Env(process.env, "WATER");
    logger.info({ env: waterEnv }, "loaded water env");
 
    const app = new FetchApplication(
      commonEnv,
      electricityEnv,
      gasEnv,
      waterEnv,
      prisma,
      appParams
    );
    await app.run(logger);
  } catch (err) {
    logger.error(err);
  }
})();