Skip to content

Commit

Permalink
fix(Repository): support uncategorized subscription (#61)
Browse files Browse the repository at this point in the history
* fix(Repository): support uncategorized subscription

Map Uncategorized subscription to "Uncategorized" category

* chore(node): fix nvmrc
  • Loading branch information
azu authored Sep 30, 2018
1 parent de3de35 commit 5a9d4e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.9.0
v10.0.0
10 changes: 10 additions & 0 deletions src/infra/repository/SubscriptionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Subscription } from "../../domain/Subscriptions/Subscription";
import { NullableRepository } from "ddd-base";
import { splice } from "@immutable-array/prototype";

const UncategorizedName = "Uncategorized";

export class SubscriptionRepository extends NullableRepository<Subscription> {
// Why not Map
// Built-in Map is difficult to be immutable
Expand Down Expand Up @@ -35,6 +37,14 @@ export class SubscriptionRepository extends NullableRepository<Subscription> {

save(aSubscription: Subscription) {
super.save(aSubscription);
if (aSubscription.categories.length === 0) {
// Map empty categories to "Uncategorized"
this.categoryMap = {
...this.categoryMap,
[UncategorizedName]: [aSubscription]
};
return;
}
aSubscription.categories.forEach(category => {
if (this.categoryMap[category] !== undefined) {
const subscriptions = this.categoryMap[category];
Expand Down

0 comments on commit 5a9d4e2

Please sign in to comment.