diff --git a/dictation_function/src/functions/licenseAutoAllocation.ts b/dictation_function/src/functions/licenseAutoAllocation.ts index a3721d1..6bddc1a 100644 --- a/dictation_function/src/functions/licenseAutoAllocation.ts +++ b/dictation_function/src/functions/licenseAutoAllocation.ts @@ -1,12 +1,4 @@ -import { - app, - InvocationContext, - Timer, - HttpRequest, - HttpHandler, - HttpResponseInit, - HttpResponse, -} from "@azure/functions"; +import { app, InvocationContext, Timer } from "@azure/functions"; import { Between, DataSource, In, MoreThan, Repository } from "typeorm"; import { User } from "../entity/user.entity"; import { Account } from "../entity/account.entity"; @@ -28,15 +20,14 @@ import { export async function licenseAutoAllocationProcessing( context: InvocationContext, - datasource: DataSource, - dateToTrigger?: Date + datasource: DataSource ): Promise { try { context.log("[IN]licenseAutoAllocationProcessing"); // ライセンスの有効期間判定用 - const currentDateZeroTime = new DateWithZeroTime(dateToTrigger); - const currentDateEndTime = new DateWithDayEndTime(dateToTrigger); + const currentDateZeroTime = new DateWithZeroTime(); + const currentDateEndTime = new DateWithDayEndTime(); // 自動更新対象の候補となるアカウントを取得 const accountRepository = datasource.getRepository(Account); @@ -387,69 +378,3 @@ class autoAllocationList { accountId: number; userIds: number[]; } - -const httpTrigger: HttpHandler = async function ( - req: HttpRequest, - context: InvocationContext -): Promise { - try { - if (req.method === "GET") { - const queryParams = new URLSearchParams(req.url.split("?")[1]); // クエリパラメータを取得 - - const requestedDate = queryParams.get("date"); - - let dateToTrigger: Date; - if (requestedDate) { - dateToTrigger = new Date(requestedDate); - } else { - dateToTrigger = new Date(); - } - context.log("[IN]licenseAutoAllocation"); - dotenv.config({ path: ".env" }); - dotenv.config({ path: ".env.local", override: true }); - let datasource: DataSource; - try { - datasource = new DataSource({ - type: "mysql", - host: process.env.DB_HOST, - port: Number(process.env.DB_PORT), - username: process.env.DB_USERNAME, - password: process.env.DB_PASSWORD, - database: process.env.DB_NAME, - entities: [User, Account, License, LicenseAllocationHistory], - }); - await datasource.initialize(); - } catch (e) { - context.log("database initialize failed."); - context.error(e); - throw e; - } - - await licenseAutoAllocationProcessing(context, datasource, dateToTrigger); - context.log("Automatic license allocation has been triggered."); - return { - status: 200, - body: "Automatic license allocation has been triggered.", - }; - } else { - context.log("Please use the GET method."); - return { - status: 400, - body: "Please use the GET method.", - }; - } - } catch (e) { - context.log("licenseAutoAllocation failed."); - context.error(e); - return { - status: 500, - body: "licenseAutoAllocation failed.", - }; - } finally { - context.log("[OUT]licenseAutoAllocation"); - } -}; - -export default httpTrigger; - -app.get("/licenseAutoAllocation", httpTrigger);