Skip to content

Commit 4e8fd98

Browse files
committed
refactor: IdField.ts now supports 'has id'
1 parent 93ee656 commit 4e8fd98

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Query/Filter/IdField.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
import type { Task } from '../../Task/Task';
12
import { Field } from './Field';
23
import { FilterOrErrorMessage } from './FilterOrErrorMessage';
4+
import { FilterInstructions } from './FilterInstructions';
35

46
export class IdField extends Field {
7+
private readonly filterInstructions: FilterInstructions = new FilterInstructions();
8+
9+
constructor() {
10+
super();
11+
this.filterInstructions.add('has id', (task: Task) => task.id.length > 0);
12+
}
13+
514
public createFilterOrErrorMessage(line: string): FilterOrErrorMessage {
6-
return FilterOrErrorMessage.fromError(line, 'Not yet implemented');
15+
const filterResult = this.filterInstructions.createFilterOrErrorMessage(line);
16+
if (filterResult.filter !== undefined) {
17+
return filterResult;
18+
}
19+
20+
return FilterOrErrorMessage.fromError(line, 'Unknown instruction');
721
}
822

923
public fieldName(): string {

tests/Query/Filter/IdField.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('id', () => {
99
expect(idField.fieldName()).toEqual('id');
1010
});
1111

12-
it.failing('by id presence', () => {
12+
it('by id presence', () => {
1313
// Arrange
1414
const filter = new IdField().createFilterOrErrorMessage('has id');
1515

0 commit comments

Comments
 (0)