This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(incidents): filter incidents (#2087)
- Loading branch information
1 parent
d1fb940
commit 5309a85
Showing
7 changed files
with
130 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import { incidents } from '../../config/pouchdb' | ||
import IncidentFilter from '../../incidents/IncidentFilter' | ||
import Incident from '../../model/Incident' | ||
import Repository from './Repository' | ||
|
||
interface SearchOptions { | ||
status: IncidentFilter | ||
} | ||
class IncidentRepository extends Repository<Incident> { | ||
constructor() { | ||
super(incidents) | ||
} | ||
|
||
async search(options: SearchOptions): Promise<Incident[]> { | ||
return super.search(IncidentRepository.getSearchCriteria(options)) | ||
} | ||
|
||
private static getSearchCriteria(options: SearchOptions): any { | ||
const statusFilter = options.status !== IncidentFilter.all ? [{ status: options.status }] : [] | ||
const selector = { | ||
$and: statusFilter, | ||
} | ||
return { | ||
selector, | ||
} | ||
} | ||
} | ||
|
||
export default new IncidentRepository() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
enum IncidentFilter { | ||
reported = 'reported', | ||
all = 'all', | ||
} | ||
|
||
export default IncidentFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5309a85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: