## 概要 [Task1961: API IF修正(LicenseSummaryInfo)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1961) - 何をどう変更したか、追加したライブラリなど API実装時に一時的にLicenseSummaryInfo2と命名していた定義を、LicenseSummaryInfoに修正。 それに伴い、既存のLicenseSummaryInfoはレスポンスに直接記載するよう修正。 openapi.jsonを再生成し、画面側のパラメータの取得の記載を修正。 - このPull Requestでの対象/対象外 storageSizeとusedSizeの取得はPBI対象外 - 影響範囲(他の機能にも影響があるか) なし ## レビューポイント - クライアント側に対する修正漏れがないか。 ## UIの変更 なし ## 動作確認状況 - ローカルでAPIの戻り値の確認と、画面にその値が表示されていることを確認。   ## 補足 - 相談、参考資料などがあれば
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 response = await this.accountService.getLicenseSummary(
|
|
body.accountId,
|
|
);
|
|
return response;
|
|
}
|
|
|
|
@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',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|