## 概要 [Task3571: データ登録ツール作成+動作確認](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3571) - 移行データの登録ツールを作成しました - 入力用jsonファイルの読み込み - アカウント・ユーザの登録 - 既存サービスを移植・微修正し呼び出し - rate_limit用のsleep実施 - ワークタイプ・ライセンス・カードライセンスの登録 - 実行についてはpostmanでの実行を考えており、clientは作成しておりません ## レビューポイント - 既存サービスからの流用が多いですが、メインの処理はfeatures/registerになるため、こちらをメインに見ていただければと思います。 ## UIの変更 - 無し ## 動作確認状況 - ローカルで動作確認 ## 補足 - 相談、参考資料などがあれば
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import { HttpException, HttpStatus, Injectable, Logger } from "@nestjs/common";
|
|
import { Context } from "../../common/log";
|
|
import {
|
|
LicensesInputFile,
|
|
WorktypesInputFile,
|
|
CardLicensesInputFile,
|
|
} from "../../common/types/types";
|
|
import { LicensesRepositoryService } from "../../repositories/licenses/licenses.repository.service";
|
|
import { WorktypesRepositoryService } from "../../repositories/worktypes/worktypes.repository.service";
|
|
import { makeErrorResponse } from "../../common/error/makeErrorResponse";
|
|
@Injectable()
|
|
export class RegisterService {
|
|
constructor(
|
|
private readonly licensesRepository: LicensesRepositoryService,
|
|
private readonly worktypesRepository: WorktypesRepositoryService
|
|
) {}
|
|
private readonly logger = new Logger(RegisterService.name);
|
|
|
|
/**
|
|
* Regist Data
|
|
* @param inputFilePath: string
|
|
*/
|
|
async registLicenseAndWorktypeData(
|
|
context: Context,
|
|
licensesInputFiles: LicensesInputFile[],
|
|
worktypesInputFiles: WorktypesInputFile[],
|
|
cardlicensesInputFiles: CardLicensesInputFile[]
|
|
): Promise<void> {
|
|
// パラメータ内容が長大なのでログには出さない
|
|
this.logger.log(
|
|
`[IN] [${context.getTrackingId()}] ${
|
|
this.registLicenseAndWorktypeData.name
|
|
}`
|
|
);
|
|
|
|
try {
|
|
this.logger.log("Licenses register start");
|
|
await this.licensesRepository.insertLicenses(context, licensesInputFiles);
|
|
this.logger.log("Licenses register end");
|
|
|
|
this.logger.log("Worktypes register start");
|
|
await this.worktypesRepository.createWorktype(
|
|
context,
|
|
worktypesInputFiles
|
|
);
|
|
this.logger.log("Worktypes register end");
|
|
|
|
this.logger.log("CardLicenses register start");
|
|
await this.licensesRepository.insertCardLicenses(
|
|
context,
|
|
cardlicensesInputFiles
|
|
);
|
|
this.logger.log("CardLicenses register end");
|
|
} catch (e) {
|
|
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
|
|
throw new HttpException(
|
|
makeErrorResponse("E009999"),
|
|
HttpStatus.INTERNAL_SERVER_ERROR
|
|
);
|
|
} finally {
|
|
this.logger.log(
|
|
`[OUT] [${context.getTrackingId()}] ${
|
|
this.registLicenseAndWorktypeData.name
|
|
}`
|
|
);
|
|
}
|
|
}
|
|
}
|