Skip to content

Commit

Permalink
Merge pull request #62 from Relewise/feat/conditions-value-relativetime
Browse files Browse the repository at this point in the history
feat: Add HasValue and RelativeDateTimeCondition
  • Loading branch information
mzanoni authored Jun 27, 2024
2 parents edf2868 + 5b2e211 commit a6286e0
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 a6286e0

Please sign in to comment.