Permalink
Browse files

feat(dao): support dates in query parameters (JS-15)

  • Loading branch information...
RangerRick committed Aug 9, 2017
1 parent c40450b commit d9884b6fa0f39ac783a48f2a0cebb6e7ea3b9d84
@@ -1,5 +1,6 @@
import {IHash} from '../internal/IHash';
import {OnmsEnum} from '../internal/OnmsEnum';
import {Util} from '../internal/Util';
import {IFilterProcessor} from '../api/IFilterProcessor';
@@ -59,11 +60,13 @@ export class V1FilterProcessor implements IFilterProcessor {
throw new OnmsError('V1 only supports one restriction comparator type!');
}
ret.comparator = comp;
let value = '' + restriction.value;
if (restriction.value instanceof OnmsEnum) {
value = (restriction.value as OnmsEnum<any>).label;
ret[restriction.attribute] = (restriction.value as OnmsEnum<any>).label;
} else if (Util.isDateObject(restriction.value)) {
ret[restriction.attribute] = Util.toDateString(restriction.value);
} else {
ret[restriction.attribute] = '' + restriction.value;
}
ret[restriction.attribute] = value;
}
}
}
@@ -1,4 +1,5 @@
import {IHash} from '../internal/IHash';
import {Util} from '../internal/Util';
import {IFilterProcessor} from '../api/IFilterProcessor';
@@ -60,7 +61,11 @@ export class V2FilterProcessor implements IFilterProcessor {
case Comparators.NOTNULL:
return restriction.value === undefined ? V2FilterProcessor.NULL_VALUE : restriction.value;
default:
return restriction.value;
if (Util.isDateObject(restriction.value)) {
return Util.toDateString(restriction.value);
} else {
return restriction.value;
}
}
}
@@ -77,4 +77,12 @@ describe('V1FilterProcessor', () => {
proc.getParameters(filter);
}).toThrow(OnmsError);
});
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000+0000', () => {
const filter = new Filter();
filter.withOrRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
const proc = new V1FilterProcessor();
expect(proc.getParameters(filter)).toMatchObject({
lastEventTime: '1976-04-14T00:00:00.000+0000'
});
});
});
@@ -89,4 +89,9 @@ describe('V2FilterProcessor', () => {
);
expect(toSearch(filter)).toEqual('id!=0;(severity==5,uei==*somethingWentWrong)');
});
it('alarm filter: lastEventTime=1976-04-14T00:00:00.000+0000', () => {
const filter = new Filter();
filter.withAndRestriction(new Restriction('lastEventTime', Comparators.EQ, new Date(198288000000)));
expect(toSearch(filter)).toEqual('lastEventTime==1976-04-14T00:00:00.000+0000');
});
});

0 comments on commit d9884b6

Please sign in to comment.