Skip to content

Commit

Permalink
feat: Add HasValue and RelativeDateTimeCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
mzanoni committed Jun 27, 2024
1 parent edf2868 commit 5b2e211
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions packages/client/src/builders/conditionBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContainsCondition, DistinctCondition, EqualsCondition, GreaterThanCondition, LessThanCondition, ValueConditionCollection, DataValueBase, DataObjectFilter, DataObjectFilterConditionBuilder } from '..';
import { ContainsCondition, DistinctCondition, EqualsCondition, GreaterThanCondition, LessThanCondition, ValueConditionCollection, DataValueBase, DataObjectFilterConditionBuilder, HasValueCondition, RelativeDateTimeCondition } from '..';

export type Conditions = ContainsCondition | DistinctCondition | EqualsCondition | GreaterThanCondition | LessThanCondition;
export type Conditions = ContainsCondition | DistinctCondition | EqualsCondition | GreaterThanCondition | LessThanCondition | HasValueCondition | RelativeDateTimeCondition;

export class ConditionBuilder {
conditions: Conditions[] = [];
Expand Down Expand Up @@ -67,9 +67,9 @@ export class ConditionBuilder {

const condition: ContainsCondition = {
$type: 'Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client',
objectFilter: {
conditions: conditionsBuilder.build(),
skip: skip,
objectFilter: {
conditions: conditionsBuilder.build(),
skip: skip,
take: take,
},
valueCollectionEvaluationMode: 'All',
Expand All @@ -80,6 +80,29 @@ export class ConditionBuilder {
return this;
}

public addHasValueCondition(negated: boolean = false) {
const condition: HasValueCondition = {
$type: 'Relewise.Client.Requests.Conditions.HasValueCondition, Relewise.Client',
negated: negated,
};
this.conditions.push(condition);

return this;
}

public addRelativeDateTimeCondition(comparison: 'Before' | 'After', unit: 'UnixMilliseconds' | 'UnixSeconds' | 'UnixMinutes', currentTimeOffset: number = 0, negated: boolean = false) {
const condition: RelativeDateTimeCondition = {
$type: 'Relewise.Client.Requests.Conditions.RelativeDateTimeCondition, Relewise.Client',
comparison: comparison,
currentTimeOffset: currentTimeOffset,
unit: unit,
negated: negated,
};
this.conditions.push(condition);

return this;
}

public build(): ValueConditionCollection | null {
return this.conditions.length === 0
? null
Expand Down

0 comments on commit 5b2e211

Please sign in to comment.