Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
#49 replace switches with maps
Browse files Browse the repository at this point in the history
  • Loading branch information
wowshakhov committed Aug 3, 2017
1 parent 7fcdba0 commit 5cd950a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,14 @@ export class PolicyViewBuilderService {
}

private getTimeToken(policy: Policy<TimePolicy>): string {
if (policy.type === PolicyType.Hourly) {
return 'POLICY_HOURLY_TIME';
}

if (policy.type === PolicyType.Daily) {
return 'POLICY_DAILY_TIME';
}

if (policy.type === PolicyType.Weekly) {
return 'POLICY_WEEKLY_TIME';
}

if (policy.type === PolicyType.Monthly) {
return 'POLICY_MONTHLY_TIME';
}

return '';
const timeTokens = {
[PolicyType.Hourly]: 'POLICY_HOURLY_TIME',
[PolicyType.Daily]: 'POLICY_DAILY_TIME',
[PolicyType.Weekly]: 'POLICY_WEEKLY_TIME',
[PolicyType.Monthly]: 'POLICY_MONTHLY_TIME'
};

return timeTokens[policy.type];
}

private getTimeZone(policy: Policy<TimePolicy>): string {
Expand Down
20 changes: 8 additions & 12 deletions src/app/snapshot/recurring-snapshots/snapshot-policy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ export class SnapshotPolicyService extends BaseBackendService<SnapshotPolicy> {
}

private transformPolicyTypeToString(type: PolicyType): string {
switch (type) {
case PolicyType.Hourly:
return 'hourly';
case PolicyType.Daily:
return 'daily';
case PolicyType.Weekly:
return 'weekly';
case PolicyType.Monthly:
return 'monthly';
default:
throw new Error('Incorrect policy mode');
}
const policyTypes = {
[PolicyType.Hourly]: 'hourly',
[PolicyType.Daily]: 'daily',
[PolicyType.Weekly]: 'weekly',
[PolicyType.Monthly]: 'monthly'
};

return policyTypes[type];
}

private transformTimePolicyToSchedule(policy: Policy<TimePolicy>): string {
Expand Down

0 comments on commit 5cd950a

Please sign in to comment.