From a4d0783652a9e5828beebd3e44e8481e5fec4bdf Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Tue, 27 Dec 2016 16:11:23 +0900 Subject: [PATCH 1/3] Remove needless type alias. These type are just an simple data type. At this time, these are over abstraction. --- src/agency/account/AgencyAccountGateway.ts | 5 ++--- src/operator/account/OperatorAccountGateway.ts | 13 ++++++------- src/public/account/AccountContract.ts | 8 -------- src/public/account/AccountGateway.ts | 8 ++++---- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/agency/account/AgencyAccountGateway.ts b/src/agency/account/AgencyAccountGateway.ts index a319e00..b291695 100644 --- a/src/agency/account/AgencyAccountGateway.ts +++ b/src/agency/account/AgencyAccountGateway.ts @@ -7,7 +7,6 @@ import {AccountGateway, AccountMap} from '../../public/account/AccountGateway'; import { AccountId, SponsorData, - SponsorDataList, dummyAgencyId, dummySponsorId, } from '../../public/account/AccountContract'; @@ -51,9 +50,9 @@ async function getSponsor(driver: FetchDriver, sponsorId: AccountId): Promise> { +async function getSponsorAll(driver: FetchDriver): Promise>> { const PATH = '/dr/account/sponsors/'; const res = await driver.get(PATH, {}); - const data = await handleOkResponseToOption(res); + const data = await handleOkResponseToOption>(res); return data; } diff --git a/src/operator/account/OperatorAccountGateway.ts b/src/operator/account/OperatorAccountGateway.ts index 0e199f4..d7a0e12 100644 --- a/src/operator/account/OperatorAccountGateway.ts +++ b/src/operator/account/OperatorAccountGateway.ts @@ -7,9 +7,8 @@ import {AgencyAccountGateway} from '../../agency/account/AgencyAccountGateway'; import { AccountId, AgencyData, - AgencyDataList, - SponsorDataList, dummyAgencyId, + SponsorData, } from '../../public/account/AccountContract'; import {AccountMap} from '../../public/account/AccountGateway'; @@ -19,7 +18,7 @@ import {AccountMap} from '../../public/account/AccountGateway'; */ export class OperatorAccountGateway extends AgencyAccountGateway { - getSponsorAllByAgency(agencyId: AccountId): Promise> { + getSponsorAllByAgency(agencyId: AccountId): Promise>> { const result = getSponsorAllByAgency(this._driver, agencyId); return result; } @@ -49,11 +48,11 @@ export class AgencyMap extends AccountMap { }; } -async function getSponsorAllByAgency(driver: FetchDriver, agencyId: AccountId): Promise> { +async function getSponsorAllByAgency(driver: FetchDriver, agencyId: AccountId): Promise>> { const PATH = '/dr/account/sponsors/'; const url = `${PATH}/?agency_id=${String(agencyId)}`; const res = await driver.get(url, {}); - const data = await handleOkResponseToOption(res); + const data = await handleOkResponseToOption>(res); return data; } @@ -65,9 +64,9 @@ async function getAgency(driver: FetchDriver, agencyId: AccountId): Promise> { +async function getAgencyAll(driver: FetchDriver): Promise>> { const PATH = '/dr/account/agencies/'; const res = await driver.get(PATH, {}); - const data = await handleOkResponseToOption(res); + const data = await handleOkResponseToOption>(res); return data; } diff --git a/src/public/account/AccountContract.ts b/src/public/account/AccountContract.ts index bb3cf1f..ac0b0ef 100644 --- a/src/public/account/AccountContract.ts +++ b/src/public/account/AccountContract.ts @@ -14,8 +14,6 @@ export interface AccountData { readonly name: string; // 社名 readonly person: string; // 担当者名 } -export type AccountDataList = Array; -export type AccountDataMap = Map; export const dummyAgencyId = 3000; export const dummySponsorId = 3000; @@ -24,13 +22,7 @@ export interface AgencyData extends AccountData { readonly role: 'agency'; } -export type AgencyDataList = Array; -export type AgencyDataMap = Map; - export interface SponsorData extends AccountData { readonly role: 'sponsor'; readonly agency_id: AccountId; // 属するAgencyData.idと一致する } - -export type SponsorDataList = Array; -export type SponsorDataMap = Map; diff --git a/src/public/account/AccountGateway.ts b/src/public/account/AccountGateway.ts index 51b9a9d..7216b7d 100644 --- a/src/public/account/AccountGateway.ts +++ b/src/public/account/AccountGateway.ts @@ -4,7 +4,7 @@ import {Result} from 'option-t/src/Result'; import {FetchDriver} from '../../lib/FetchDriver'; import {handleOkResponseToResult} from '../../lib/FetchHelper'; -import {AccountId, AccountData, AccountDataList, AccountDataMap} from './AccountContract'; +import {AccountId, AccountData} from './AccountContract'; export type AccountInfoResult = Result; @@ -31,14 +31,14 @@ export class AccountGateway { } export abstract class AccountMap { - protected _map: AccountDataMap; + protected _map: Map; protected _dummyAccount: AccountData; - constructor(accountList: Option) { + constructor(accountList: Option>) { this._map = this._generateAccountMap(accountList); } - _generateAccountMap(accountList: Option): AccountDataMap { + _generateAccountMap(accountList: Option>): Map { const map = new Map(); for (const row of accountList.unwrapOr([])) { map.set(row.id, row); From 96253a7669a4e3239607f0773eff52d91bf4c02c Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Tue, 27 Dec 2016 16:13:02 +0900 Subject: [PATCH 2/3] Constant should be UPPER_SNAKE_CASE --- src/agency/account/AgencyAccountGateway.ts | 8 ++++---- src/operator/account/OperatorAccountGateway.ts | 4 ++-- src/public/account/AccountContract.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/agency/account/AgencyAccountGateway.ts b/src/agency/account/AgencyAccountGateway.ts index b291695..83b34ce 100644 --- a/src/agency/account/AgencyAccountGateway.ts +++ b/src/agency/account/AgencyAccountGateway.ts @@ -7,8 +7,8 @@ import {AccountGateway, AccountMap} from '../../public/account/AccountGateway'; import { AccountId, SponsorData, - dummyAgencyId, - dummySponsorId, + DUMMY_AGENCY_ID, + DUMMY_SPONSOR_ID, } from '../../public/account/AccountContract'; /** @@ -32,9 +32,9 @@ export class AgencyAccountGateway extends AccountGateway { class SponsorMap extends AccountMap { protected _dummyAccount: SponsorData = { - id: dummySponsorId, + id: DUMMY_SPONSOR_ID, exchange_id: 1, - agency_id: dummyAgencyId, + agency_id: DUMMY_AGENCY_ID, role: 'sponsor', uuid: '00000000000000000000000000000000', name: '不明な広告主', diff --git a/src/operator/account/OperatorAccountGateway.ts b/src/operator/account/OperatorAccountGateway.ts index d7a0e12..1bc3bf5 100644 --- a/src/operator/account/OperatorAccountGateway.ts +++ b/src/operator/account/OperatorAccountGateway.ts @@ -7,7 +7,7 @@ import {AgencyAccountGateway} from '../../agency/account/AgencyAccountGateway'; import { AccountId, AgencyData, - dummyAgencyId, + DUMMY_AGENCY_ID, SponsorData, } from '../../public/account/AccountContract'; import {AccountMap} from '../../public/account/AccountGateway'; @@ -39,7 +39,7 @@ export class OperatorAccountGateway extends AgencyAccountGateway { export class AgencyMap extends AccountMap { protected _dummyAccount: AgencyData = { - id: dummyAgencyId, + id: DUMMY_AGENCY_ID, exchange_id: 1, role: 'agency', uuid: '00000000000000000000000000000000', diff --git a/src/public/account/AccountContract.ts b/src/public/account/AccountContract.ts index ac0b0ef..69f9769 100644 --- a/src/public/account/AccountContract.ts +++ b/src/public/account/AccountContract.ts @@ -15,8 +15,8 @@ export interface AccountData { readonly person: string; // 担当者名 } -export const dummyAgencyId = 3000; -export const dummySponsorId = 3000; +export const DUMMY_AGENCY_ID = 3000; +export const DUMMY_SPONSOR_ID = 3000; export interface AgencyData extends AccountData { readonly role: 'agency'; From 3f94b9428bc97ffed1f527bca63c90edafa5637c Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Tue, 27 Dec 2016 16:15:14 +0900 Subject: [PATCH 3/3] Separate generateAccountMap from AccountMap. This method does not need to be the part of AccountMap. --- src/public/account/AccountGateway.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/public/account/AccountGateway.ts b/src/public/account/AccountGateway.ts index 7216b7d..7915335 100644 --- a/src/public/account/AccountGateway.ts +++ b/src/public/account/AccountGateway.ts @@ -35,15 +35,7 @@ export abstract class AccountMap { protected _dummyAccount: AccountData; constructor(accountList: Option>) { - this._map = this._generateAccountMap(accountList); - } - - _generateAccountMap(accountList: Option>): Map { - const map = new Map(); - for (const row of accountList.unwrapOr([])) { - map.set(row.id, row); - } - return map; + this._map = generateAccountMap(accountList); } get(accountId: AccountId): AccountData { @@ -56,6 +48,14 @@ export abstract class AccountMap { } } +function generateAccountMap(accountList: Option>): Map { + const map = new Map(); + for (const row of accountList.unwrapOr([])) { + map.set(row.id, row); + } + return map; +} + export async function getAccountInformation(driver: FetchDriver, param?: GetAccountInfoArgs): Promise { const PATH = '/dr/account/me'; let url = PATH;