## 概要 [Task1846: API実装(第五階層用ライセンス情報取得API)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1846) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど accounts.controller.tsからaccountService.getLicenseSummaryを呼び出す。 一度のトランザクションで処理を行うよう、serviceとrepositoryをリファクタリング。 license.entity.tsにはライセンス系のテーブルで不足していたエンティティを追加。 - このPull Requestでの対象/対象外 Storage Sizeの値はPBI1203では対象外のため0固定 Used Sizeの値はPBI1203では対象外のため0固定 LicenseSummaryInfo2と定義している個所は、別タスクで修正します。 [タスク 1961: API IF修正(LicenseSummaryInfo)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/OMDSDictation/_sprints/taskboard/OMDSDictation%20%E3%83%81%E3%83%BC%E3%83%A0/OMDSDictation/%E3%82%B9%E3%83%97%E3%83%AA%E3%83%B3%E3%83%88%2011-1?workitem=1961) - 影響範囲(他の機能にも影響があるか) 新規追加のため、なし ## レビューポイント - 特にレビューしてほしい箇所 ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 PostmanでAPI実行。 各ライセンス数値が期待通りの結果であることを確認。  ## 補足 テスト内容は、添付のテストデータを参照ください。 [テストデータ.xlsx](https://dev.azure.com/ODMSCloud/6023ff7b-d41c-4fa7-9c6f-f576ba48c07c/_apis/git/repositories/302da463-a2d7-40f9-b2bb-6e8edf324fa9/pullRequests/142/attachments/%E3%83%86%E3%82%B9%E3%83%88%E3%83%87%E3%83%BC%E3%82%BF.xlsx)
249 lines
6.5 KiB
TypeScript
249 lines
6.5 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
HttpException,
|
|
HttpStatus,
|
|
Post,
|
|
Get,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import {
|
|
ApiOperation,
|
|
ApiResponse,
|
|
ApiTags,
|
|
ApiBearerAuth,
|
|
} from '@nestjs/swagger';
|
|
import { ErrorResponse } from '../../common/error/types/types';
|
|
import { Request } from 'express';
|
|
import { AccountsService } from './accounts.service';
|
|
import {
|
|
CreateAccountRequest,
|
|
CreateAccountResponse,
|
|
GetLicenseSummaryRequest,
|
|
GetLicenseSummaryResponse,
|
|
GetMyAccountResponse,
|
|
GetTypistGroupsResponse,
|
|
GetTypistsResponse,
|
|
} from './types/types';
|
|
import { USER_ROLES, ADMIN_ROLES } from '../../constants';
|
|
import { AuthGuard } from '../../common/guards/auth/authguards';
|
|
import { RoleGuard } from '../../common/guards/role/roleguards';
|
|
//import { CryptoService } from '../../gateways/crypto/crypto.service';
|
|
import { retrieveAuthorizationToken } from '../../common/http/helper';
|
|
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
|
|
import { isVerifyError, verify } from '../../common/jwt';
|
|
import { AccessToken } from '../../common/token';
|
|
//import { confirmPermission } from '../../common/auth/auth';
|
|
import jwt from 'jsonwebtoken';
|
|
|
|
@ApiTags('accounts')
|
|
@Controller('accounts')
|
|
export class AccountsController {
|
|
constructor(
|
|
private readonly accountService: AccountsService, //private readonly cryptoService: CryptoService,
|
|
) {}
|
|
|
|
@Post()
|
|
@ApiResponse({
|
|
status: HttpStatus.OK,
|
|
type: CreateAccountResponse,
|
|
description: '成功時のレスポンス',
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.BAD_REQUEST,
|
|
description: '登録済みユーザーからの登録など',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: '想定外のサーバーエラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiOperation({ operationId: 'createAccount' })
|
|
async createAccount(
|
|
@Body() body: CreateAccountRequest,
|
|
): Promise<CreateAccountResponse> {
|
|
const {
|
|
companyName,
|
|
country,
|
|
dealerAccountId,
|
|
adminMail,
|
|
adminPassword,
|
|
adminName,
|
|
acceptedTermsVersion,
|
|
} = body;
|
|
const role = USER_ROLES.NONE;
|
|
|
|
await this.accountService.createAccount(
|
|
companyName,
|
|
country,
|
|
dealerAccountId,
|
|
adminMail,
|
|
adminPassword,
|
|
adminName,
|
|
role,
|
|
acceptedTermsVersion,
|
|
);
|
|
|
|
return {};
|
|
}
|
|
|
|
@ApiResponse({
|
|
status: HttpStatus.OK,
|
|
type: GetLicenseSummaryResponse,
|
|
description: '成功時のレスポンス',
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.UNAUTHORIZED,
|
|
description: '認証エラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: '想定外のサーバーエラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiOperation({
|
|
operationId: 'getLicenseSummary',
|
|
description: '指定したアカウントのライセンス集計情報を取得します',
|
|
})
|
|
@ApiBearerAuth()
|
|
@UseGuards(AuthGuard)
|
|
@UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] }))
|
|
@Post('licenses/summary')
|
|
async getLicenseSummary(
|
|
@Req() req: Request,
|
|
@Body() body: GetLicenseSummaryRequest,
|
|
): Promise<GetLicenseSummaryResponse> {
|
|
console.log(req.header('Authorization'));
|
|
console.log(body);
|
|
|
|
const info = await this.accountService.getLicenseSummary(body.accountId);
|
|
return {
|
|
licenseSummaryInfo: info,
|
|
};
|
|
}
|
|
|
|
@ApiResponse({
|
|
status: HttpStatus.OK,
|
|
type: GetMyAccountResponse,
|
|
description: '成功時のレスポンス',
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.BAD_REQUEST,
|
|
description: '該当アカウントがDBに存在しない場合',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.UNAUTHORIZED,
|
|
description: '認証エラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: '想定外のサーバーエラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiOperation({
|
|
operationId: 'getMyAccount',
|
|
description: 'ログインしているユーザーのアカウント情報を取得します',
|
|
})
|
|
@ApiBearerAuth()
|
|
@UseGuards(AuthGuard)
|
|
@UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] }))
|
|
@Get('me')
|
|
async getMyAccount(@Req() req: Request): Promise<GetMyAccountResponse> {
|
|
console.log(req.header('Authorization'));
|
|
|
|
// アクセストークン取得
|
|
const accessToken = retrieveAuthorizationToken(req);
|
|
const payload = jwt.decode(accessToken, { json: true }) as AccessToken;
|
|
//アカウントID取得処理
|
|
const accountId = await this.accountService.getMyAccountInfo(payload);
|
|
return {
|
|
account: {
|
|
accountId: accountId,
|
|
},
|
|
};
|
|
}
|
|
|
|
@ApiResponse({
|
|
status: HttpStatus.OK,
|
|
type: GetTypistsResponse,
|
|
description: '成功時のレスポンス',
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.UNAUTHORIZED,
|
|
description: '認証エラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: '想定外のサーバーエラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiOperation({
|
|
operationId: 'getTypists',
|
|
description:
|
|
'ログインしているユーザーのアカウント配下のタイピスト一覧を取得します',
|
|
})
|
|
@ApiBearerAuth()
|
|
@UseGuards(AuthGuard)
|
|
@Get('typists')
|
|
async getTypists(@Req() req: Request): Promise<GetTypistsResponse> {
|
|
console.log(req.header('Authorization'));
|
|
return {
|
|
typists: [
|
|
{
|
|
id: 1,
|
|
name: 'AAA',
|
|
},
|
|
{
|
|
id: 2,
|
|
name: 'BBB',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
@ApiResponse({
|
|
status: HttpStatus.OK,
|
|
type: GetTypistGroupsResponse,
|
|
description: '成功時のレスポンス',
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.UNAUTHORIZED,
|
|
description: '認証エラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: '想定外のサーバーエラー',
|
|
type: ErrorResponse,
|
|
})
|
|
@ApiOperation({
|
|
operationId: 'getTypistGroups',
|
|
description:
|
|
'ログインしているユーザーのアカウント配下のタイピストグループ一覧を取得します',
|
|
})
|
|
@ApiBearerAuth()
|
|
@UseGuards(AuthGuard)
|
|
@Get('typist-groups')
|
|
async getTypistGroups(@Req() req: Request): Promise<GetTypistGroupsResponse> {
|
|
console.log(req.header('Authorization'));
|
|
return {
|
|
typistGroups: [
|
|
{
|
|
id: 1,
|
|
name: 'GroupA',
|
|
},
|
|
{
|
|
id: 2,
|
|
name: 'GroupB',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|