Skip to content

Commit

Permalink
fix(database): allow null values for equalTo, etc.
Browse files Browse the repository at this point in the history
Values passed for equalTo, startAt and endAt should be allowed to be
null.

Closes #704.
  • Loading branch information
cartant authored and katowulf committed Dec 12, 2016
1 parent 4712c5b commit 70a3e94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/database/firebase_list_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export function FirebaseListFactory (
}

// check equalTo
if (!utils.isNil(query.equalTo)) {
queried = queried.equalTo(query.equalTo);
if (utils.hasKey(query, "equalTo")) {
queried = queried.equalTo(query.equalTo);

if (!utils.isNil(query.startAt) || query.endAt) {
if (utils.hasKey(query, "startAt") || utils.hasKey(query, "endAt")) {
throw new Error('Query Error: Cannot use startAt or endAt with equalTo.');
}

Expand All @@ -69,11 +69,11 @@ export function FirebaseListFactory (
}

// check startAt
if (!utils.isNil(query.startAt)) {
if (utils.hasKey(query, "startAt")) {
queried = queried.startAt(query.startAt);
}

if (!utils.isNil(query.endAt)) {
if (utils.hasKey(query, "endAt")) {
queried = queried.endAt(query.endAt);
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export function isNil(obj: any): boolean {
return obj === undefined || obj === null;
}

export function hasKey(obj: Object, key: string): boolean {
return obj && obj[key] !== undefined;
}

export function isString(value: any): boolean {
return typeof value === 'string';
}
Expand Down

0 comments on commit 70a3e94

Please sign in to comment.