Merged PR 309: Dealer取得API実装
## 概要 [Task2348: Dealer取得API実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2348) - アカウント登録画面で呼ぶDealer取得APIを実装 ## レビューポイント - 取得条件は正しいか - テストケースは足りているか - DBエラーによるエラーケースは作成しても効果が薄いと思ったため作成していません ## UIの変更 ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
d70b471d55
commit
712efb8bb7
@ -423,14 +423,6 @@ export class AccountsController {
|
||||
})
|
||||
@ApiOperation({ operationId: 'getDealers' })
|
||||
async getDealers(): Promise<GetDealersResponse> {
|
||||
return {
|
||||
dealers: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Dealer1',
|
||||
country: 'US',
|
||||
},
|
||||
],
|
||||
};
|
||||
return await this.accountService.getDealers();
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ import {
|
||||
import { DataSource } from 'typeorm';
|
||||
import { makeTestingModule } from '../../common/test/modules';
|
||||
import { AccountsService } from './accounts.service';
|
||||
import { TIERS } from '../../constants';
|
||||
|
||||
describe('AccountsService', () => {
|
||||
it('アカウントに紐づくライセンス情報を取得する', async () => {
|
||||
@ -549,3 +550,74 @@ describe('getOrderHistories', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDealers', () => {
|
||||
let source: DataSource = null;
|
||||
beforeEach(async () => {
|
||||
source = new DataSource({
|
||||
type: 'sqlite',
|
||||
database: ':memory:',
|
||||
logging: false,
|
||||
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
|
||||
synchronize: true, // trueにすると自動的にmigrationが行われるため注意
|
||||
});
|
||||
return source.initialize();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await source.destroy();
|
||||
source = null;
|
||||
});
|
||||
|
||||
it('Dealerを取得できる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const { accountId: accountId_1 } = await createAccount(
|
||||
source,
|
||||
1,
|
||||
TIERS.TIER4,
|
||||
'DEALER_1',
|
||||
);
|
||||
const { accountId: accountId_2 } = await createAccount(
|
||||
source,
|
||||
2,
|
||||
TIERS.TIER4,
|
||||
'DEALER_2',
|
||||
);
|
||||
const { accountId: accountId_3 } = await createAccount(
|
||||
source,
|
||||
3,
|
||||
TIERS.TIER4,
|
||||
'DEALER_3',
|
||||
);
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
expect(await service.getDealers()).toEqual({
|
||||
dealers: [
|
||||
{
|
||||
country: 'JP',
|
||||
id: accountId_1,
|
||||
name: 'DEALER_1',
|
||||
},
|
||||
{
|
||||
country: 'JP',
|
||||
id: accountId_2,
|
||||
name: 'DEALER_2',
|
||||
},
|
||||
{
|
||||
country: 'JP',
|
||||
id: accountId_3,
|
||||
name: 'DEALER_3',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
it('0件でもDealerを取得できる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
expect(await service.getDealers()).toEqual({
|
||||
dealers: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -22,6 +22,8 @@ import {
|
||||
PartnerLicenseInfo,
|
||||
GetOrderHistoriesResponse,
|
||||
LicenseOrder,
|
||||
GetDealersResponse,
|
||||
Dealer,
|
||||
GetMyAccountResponse,
|
||||
} from './types/types';
|
||||
import { DateWithZeroTime } from '../licenses/types/types';
|
||||
@ -263,7 +265,7 @@ export class AccountsService {
|
||||
account: {
|
||||
accountId: userInfo.account_id,
|
||||
companyName: accountInfo.company_name,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -584,4 +586,33 @@ export class AccountsService {
|
||||
this.logger.log(`[OUT] ${this.getOrderHistories.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
// dealersのアカウント情報を取得する
|
||||
async getDealers(): Promise<GetDealersResponse> {
|
||||
this.logger.log(`[IN] ${this.getDealers.name}`);
|
||||
|
||||
try {
|
||||
const dealerAccounts = await this.accountRepository.findDealerAccounts();
|
||||
|
||||
const dealers: GetDealersResponse = {
|
||||
dealers: dealerAccounts.map((dealerAccount): Dealer => {
|
||||
return {
|
||||
id: dealerAccount.id,
|
||||
name: dealerAccount.company_name,
|
||||
country: dealerAccount.country,
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
return dealers;
|
||||
} catch (e) {
|
||||
this.logger.error(e);
|
||||
throw new HttpException(
|
||||
makeErrorResponse('E009999'),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} finally {
|
||||
this.logger.log(`[OUT] ${this.getDealers.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import {
|
||||
import {
|
||||
LICENSE_ALLOCATED_STATUS,
|
||||
LICENSE_STATUS_ISSUE_REQUESTING,
|
||||
TIERS,
|
||||
} from '../../constants';
|
||||
import {
|
||||
LicenseSummaryInfo,
|
||||
@ -551,4 +552,18 @@ export class AccountsRepositoryService {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Dealer(Tier4)アカウント情報を取得する
|
||||
* @returns dealer accounts
|
||||
*/
|
||||
async findDealerAccounts(): Promise<Account[]> {
|
||||
const accounts = await this.dataSource.getRepository(Account).find({
|
||||
where: {
|
||||
tier: TIERS.TIER4,
|
||||
},
|
||||
});
|
||||
|
||||
return accounts;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user